Skip to content

Commit 9698b90

Browse files
committed
#165 pb cron et expiration des invitations
#165
1 parent e827010 commit 9698b90

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

apps/api/defaults/cron/identities-init-invitation-expire.yml renamed to apps/api/defaults/cron/identities-init-expire.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tasks:
2-
- name: "identities-init-invitation-expire"
2+
- name: "identities-init-expire"
33
description: "Expiration des invitations d'initialisation de compte"
44
enabled: true
55
schedule: "1 * * * *" # Tous les jours à 08:00
6-
handler: "identities-init-invitation-expire"
6+
handler: "identities-init-expire"
77
options:

apps/api/src/core/cron/_functions/cron-command-options.function.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ function getHandlerDescriptor(handler: string) {
88
return getCronConsoleHandlers().find((entry) => entry.handler === handler);
99
}
1010

11+
/**
12+
* Mots de la commande console d'un handler : utilise `command` déclaré via @CronConsoleHandler,
13+
* sinon (handler non déclaré) découpe l'identifiant sur les tirets.
14+
*/
15+
export function resolveCronConsoleCommandWords(handler: string): string[] {
16+
const descriptor = getHandlerDescriptor(handler);
17+
return (descriptor?.command || handler.replace(/-/g, ' ')).split(/\s+/).filter(Boolean);
18+
}
19+
1120
export function resolveCronConsoleArgumentFlag(argument: CronConsoleHandlerArgument): string {
1221
return argument.flag || `--${argument.name}`;
1322
}

apps/api/src/core/cron/cron-hooks.service.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { loadcronTasks } from './_functions/load-cron-tasks.function';
99
import { ConfigService } from '@nestjs/config';
1010
import { createHandlerLogger } from '~/_common/functions/handler-logger';
1111
import { resolveConfigVariables } from '~/_common/functions/resolve-config-variables.function';
12-
import { buildCronCommandArgs } from './_functions/cron-command-options.function';
12+
import { buildCronCommandArgs, resolveCronConsoleCommandWords } from './_functions/cron-command-options.function';
1313

1414
@Injectable()
1515
export class CronHooksService {
@@ -177,7 +177,9 @@ export class CronHooksService {
177177
}
178178

179179
// Supprimer les jobs qui ne sont plus dans les tâches désirées
180-
for (const [name, job] of existingJobs) {
180+
// Itère sur une copie : getCronJobs() renvoie la Map interne du registre, et un delete + add
181+
// sur la même clé la replace en fin de Map, ce qui la ferait revisiter indéfiniment.
182+
for (const [name, job] of Array.from(existingJobs)) {
181183
if (!name.startsWith('cron-task-')) continue;
182184

183185
const desired = desiredTasks.get(name);
@@ -301,7 +303,7 @@ export class CronHooksService {
301303
const { positionalArgs, flagArgs } = buildCronCommandArgs(handler, resolvedOptions);
302304

303305
const cmd = 'yarn';
304-
const cmdArgs = ['run', 'console', ...handler.split('-'), ...positionalArgs, ...flagArgs];
306+
const cmdArgs = ['run', 'console', ...resolveCronConsoleCommandWords(handler), ...positionalArgs, ...flagArgs];
305307

306308
const handlerLogger = createHandlerLogger(this.configService, name);
307309
this.logger.log(`Spawning command: ${cmd} ${cmdArgs.join(' ')}`);

apps/api/src/management/identities/identities.command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ type IdentitiesInitExpireOptions = {
331331
};
332332

333333
@CronConsoleHandler({
334-
handler: 'identities-init-invitation-expire',
334+
handler: 'identities-init-expire',
335335
command: 'identities init expire',
336336
label: "Expiration des invitations d'initialisation de compte",
337337
arguments: [

0 commit comments

Comments
 (0)