Skip to content

Commit 7d91ed8

Browse files
authored
feat(cron): add logging for skipped cron jobs (#2807)
* Fix race condition in ProcessService initialization This reverts the regression introduced in commit 0727fed which caused all processes to be treated as "disabled" during the initial startup window before async resyncDisabledProcesses() completed. Changes: - Initialize DisabledProcesses with empty map {} instead of undefined - Simplify DisabledProcess() to only return true when explicitly disabled - Add synchronous initialization from Config.disabledProcesses() - Add logging to DfxCronService when jobs are skipped due to disabled process The previous logic returned true (disabled) when DisabledProcesses was undefined, causing a race condition where cron jobs triggered before the async initialization completed would be silently skipped. * style: fix prettier formatting * refactor: keep only logging, revert race condition fix Keep the useful logging for skipped cron jobs but revert the ProcessService changes since the race condition is self-healing and hasn't caused issues in 6 months.
1 parent a9bc5fe commit 7d91ed8

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/shared/services/dfx-cron.service.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { DFX_CRONJOB_PARAMS, DfxCronExpression, DfxCronParams } from 'src/shared
88
import { LockClass } from 'src/shared/utils/lock';
99
import { Util } from 'src/shared/utils/util';
1010
import { CustomCronExpression } from '../utils/custom-cron-expression';
11+
import { DfxLogger } from './dfx-logger';
1112

1213
interface CronJobData {
1314
instance: object;
@@ -18,6 +19,8 @@ interface CronJobData {
1819

1920
@Injectable()
2021
export class DfxCronService implements OnModuleInit {
22+
private readonly logger = new DfxLogger(DfxCronService);
23+
2124
constructor(
2225
private readonly discovery: DiscoveryService,
2326
private readonly metadataScanner: MetadataScanner,
@@ -59,8 +62,15 @@ export class DfxCronService implements OnModuleInit {
5962
}
6063

6164
private wrapFunction(data: CronJobData) {
65+
const context = { target: data.instance.constructor.name, method: data.methodName };
66+
6267
return async (...args: any) => {
63-
if (data.params.process && DisabledProcess(data.params.process)) return;
68+
if (data.params.process && DisabledProcess(data.params.process)) {
69+
this.logger.verbose(
70+
`Skipping ${context.target}::${context.method} - process ${data.params.process} is disabled`,
71+
);
72+
return;
73+
}
6474

6575
if (data.params.useDelay ?? true) await this.cronJobDelay(data.params.expression);
6676

0 commit comments

Comments
 (0)