Skip to content

Commit

Permalink
fix: ajout d'un job de maj ponctuel de deca (#3700)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Gaucher <[email protected]>
  • Loading branch information
Pomarom and Pomarom authored Jun 6, 2024
1 parent 4da4323 commit 46086fe
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
6 changes: 6 additions & 0 deletions server/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ program
.option("-f, --full", "Récupère l'intégralité des données disponibles via l'API Deca", false)
.action(createJobAction("hydrate:contrats-deca-raw"));

program
.command("update:organismes-deca-transmitter")
.description("Mise a jour des effectifs DECA désynchronisé")
.option("-q, --queued", "Run job asynchronously", false)
.action(createJobAction("update:organismes-deca-transmitter"));

program
.command("dev:generate-open-api")
.description("Création/maj du fichier open-api.json")
Expand Down
14 changes: 14 additions & 0 deletions server/src/common/actions/organismes/organismes.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,20 @@ export const updateOrganismesHasTransmittedWithHierarchy = async (
);
};

export const updateDecaCompatibilityFromOrganismeId = async (organismeId: ObjectId, isDecaCompatible: boolean) => {
await effectifsDECADb().updateMany(
{
organisme_id: organismeId,
},
{
$set: {
is_deca_compatible: isDecaCompatible,
},
},
{ bypassDocumentValidation: true }
);
};

/**
* Génération d'une api key s'il n'existe pas
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { captureException } from "@sentry/node";

import { updateOrganismesHasTransmittedWithHierarchy } from "@/common/actions/organismes/organismes.actions";
import {
updateOrganismesHasTransmittedWithHierarchy,
updateDecaCompatibilityFromOrganismeId,
} from "@/common/actions/organismes/organismes.actions";
import logger from "@/common/logger";
import { organismesDb } from "@/common/model/collections";

Expand All @@ -20,3 +23,18 @@ export const hydrateOrganismesEffectifsCountWithHierarchy = async () => {
captureException(err);
}
};

export const updateOrganismesDecaTransmitter = async () => {
try {
logger.info(`updateOrganismesDecaTransmitter: processing`);
const organismesCursor = organismesDb().find({ is_transmission_target: true });
while (await organismesCursor.hasNext()) {
const organisme = await organismesCursor.next();
if (organisme) {
await updateDecaCompatibilityFromOrganismeId(organisme._id, false);
}
}
} catch (err) {
captureException(err);
}
};
10 changes: 9 additions & 1 deletion server/src/jobs/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import { hydrateOrganismesOPCOs } from "./hydrate/hydrate-organismes-opcos";
import { hydrateRNCP } from "./hydrate/hydrate-rncp";
import { hydrateROME } from "./hydrate/hydrate-rome";
import { hydrateOpenApi } from "./hydrate/open-api/hydrate-open-api";
import { hydrateOrganismesEffectifsCountWithHierarchy } from "./hydrate/organismes/hydrate-effectifs-count-with-hierarchy";
import {
hydrateOrganismesEffectifsCountWithHierarchy,
updateOrganismesDecaTransmitter,
} from "./hydrate/organismes/hydrate-effectifs-count-with-hierarchy";
import { hydrateOrganismesEffectifsCount } from "./hydrate/organismes/hydrate-effectifs_count";
import { hydrateOrganismesFromReferentiel } from "./hydrate/organismes/hydrate-organismes";
import { hydrateOrganismesBassinEmploi } from "./hydrate/organismes/hydrate-organismes-bassinEmploi";
Expand Down Expand Up @@ -307,6 +310,11 @@ export async function setupJobProcessor() {
return updateAllOrganismesRelatedFormations();
},
},
"update:organismes-deca-transmitter": {
handler: async () => {
return updateOrganismesDecaTransmitter();
},
},
"hydrate:opcos": {
handler: async () => {
return hydrateOrganismesOPCOs();
Expand Down

0 comments on commit 46086fe

Please sign in to comment.