Skip to content

Commit

Permalink
fix: mise a jour des params de la fonction hydrateEffectifsComputedTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pomarom committed Dec 16, 2024
1 parent d8e178b commit 277c8e9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ program
.description("Manually trigger the update of the computed")
.option("--id <string>", "Id de l'organisme", (organismeId) => organismeId, null)
.option("-q, --queued", "Run job asynchronously", false)
.action(createJobAction("hydrate:effectifs:update_computed_statut_month"));
.action(createJobAction("hydrate:effectifs:update_computed_statut"));

program
.command("job:run")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { captureException } from "@sentry/node";
import { IEffectif } from "shared/models";
import { substractDaysUTC } from "shared/utils";

import { updateEffectifStatut } from "@/common/actions/effectifs.statut.actions";
import logger from "@/common/logger";
Expand All @@ -23,11 +22,6 @@ export async function hydrateEffectifsComputedTypes(
const BULK_SIZE = 100;
let bulkEffectifs: IEffectif[] = [];

const computedQuery = {
...query,
updated_at: { $lt: substractDaysUTC(evaluationDate, 7) },
};

const processEffectif = async (eff: IEffectif) => {
if (eff) {
const isSuccess = await updateEffectifStatut(eff, evaluationDate);
Expand All @@ -40,7 +34,7 @@ export async function hydrateEffectifsComputedTypes(
};

try {
const cursor = effectifsDb().find(computedQuery);
const cursor = effectifsDb().find(query);

while (await cursor.hasNext()) {
const effectif: IEffectif | null = await cursor.next();
Expand Down
6 changes: 4 additions & 2 deletions server/src/jobs/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { addJob, initJobProcessor } from "job-processor";
import { MongoError, ObjectId, WithId } from "mongodb";
import { MOTIF_SUPPRESSION } from "shared/constants";
import type { IEffectif } from "shared/models";
import { getAnneesScolaireListFromDate } from "shared/utils";
import { getAnneesScolaireListFromDate, substractDaysUTC } from "shared/utils";

import { softDeleteEffectif } from "@/common/actions/effectifs.actions";
import logger from "@/common/logger";
Expand Down Expand Up @@ -186,10 +186,12 @@ export async function setupJobProcessor() {
"hydrate:effectifs:update_computed_statut": {
handler: async (job, signal) => {
const organismeId = (job.payload?.id as string) ? new ObjectId(job.payload?.id as string) : null;
const evaluationDate = new Date();
return hydrateEffectifsComputedTypes(
{
query: {
annee_scolaire: { $in: getAnneesScolaireListFromDate(new Date()) },
annee_scolaire: { $in: getAnneesScolaireListFromDate(evaluationDate) },
updated_at: { $lt: substractDaysUTC(evaluationDate, 7) },
...(organismeId ? { organisme_id: organismeId } : {}),
},
},
Expand Down

0 comments on commit 277c8e9

Please sign in to comment.