From 9d839299e2c394efa970f216515d82d21748eaf1 Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Mon, 15 Jan 2024 12:50:32 +0100 Subject: [PATCH] fix: differentiated interval and initial schedule call (#5896) Differentiate log lines so we can see if it happens on every call, or just on the initial call. --- src/lib/features/maintenance/maintenance-service.ts | 2 +- src/lib/features/scheduler/scheduler-service.test.ts | 12 ++++++------ src/lib/features/scheduler/scheduler-service.ts | 6 ++++-- src/lib/services/scheduler-service.test.ts | 8 ++++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/lib/features/maintenance/maintenance-service.ts b/src/lib/features/maintenance/maintenance-service.ts index 8686762ede..8748a0e1ee 100644 --- a/src/lib/features/maintenance/maintenance-service.ts +++ b/src/lib/features/maintenance/maintenance-service.ts @@ -17,7 +17,7 @@ export default class MaintenanceService implements IMaintenanceStatus { constructor(config: IUnleashConfig, settingService: SettingService) { this.config = config; - this.logger = config.getLogger('services/pat-service.ts'); + this.logger = config.getLogger('services/maintenance-service.ts'); this.settingService = settingService; } diff --git a/src/lib/features/scheduler/scheduler-service.test.ts b/src/lib/features/scheduler/scheduler-service.test.ts index 87a55938d5..8c8f71c840 100644 --- a/src/lib/features/scheduler/scheduler-service.test.ts +++ b/src/lib/features/scheduler/scheduler-service.test.ts @@ -177,8 +177,8 @@ test('Can handle crash of a async job', async () => { schedulerService.stop(); expect(getRecords()).toEqual([ - ['scheduled job failed | id: test-id-10 | async reason'], - ['scheduled job failed | id: test-id-10 | async reason'], + ['initial scheduled job failed | id: test-id-10 | async reason'], + ['interval scheduled job failed | id: test-id-10 | async reason'], ]); }); @@ -197,8 +197,8 @@ test('Can handle crash of a sync job', async () => { schedulerService.stop(); expect(getRecords()).toEqual([ - ['scheduled job failed | id: test-id-11 | Error: sync reason'], - ['scheduled job failed | id: test-id-11 | Error: sync reason'], + ['initial scheduled job failed | id: test-id-11 | Error: sync reason'], + ['interval scheduled job failed | id: test-id-11 | Error: sync reason'], ]); }); @@ -217,8 +217,8 @@ test('Can handle crash of a async job', async () => { schedulerService.stop(); expect(getRecords()).toEqual([ - ['scheduled job failed | id: test-id-10 | async reason'], - ['scheduled job failed | id: test-id-10 | async reason'], + ['initial scheduled job failed | id: test-id-10 | async reason'], + ['interval scheduled job failed | id: test-id-10 | async reason'], ]); }); diff --git a/src/lib/features/scheduler/scheduler-service.ts b/src/lib/features/scheduler/scheduler-service.ts index 867f4e8fef..1a6b8dc344 100644 --- a/src/lib/features/scheduler/scheduler-service.ts +++ b/src/lib/features/scheduler/scheduler-service.ts @@ -52,7 +52,7 @@ export class SchedulerService { } } catch (e) { this.logger.error( - `scheduled job failed | id: ${id} | ${e}`, + `interval scheduled job failed | id: ${id} | ${e}`, ); } }, timeMs).unref(), @@ -64,7 +64,9 @@ export class SchedulerService { await runScheduledFunctionWithEvent(); } } catch (e) { - this.logger.error(`scheduled job failed | id: ${id} | ${e}`); + this.logger.error( + `initial scheduled job failed | id: ${id} | ${e}`, + ); } } diff --git a/src/lib/services/scheduler-service.test.ts b/src/lib/services/scheduler-service.test.ts index 7f96f80ac8..7321b0d4dd 100644 --- a/src/lib/services/scheduler-service.test.ts +++ b/src/lib/services/scheduler-service.test.ts @@ -101,8 +101,8 @@ test('Can handle crash of a async job', async () => { schedulerService.stop(); expect(getRecords()).toEqual([ - ['scheduled job failed | id: test-id-10 | async reason'], - ['scheduled job failed | id: test-id-10 | async reason'], + ['initial scheduled job failed | id: test-id-10 | async reason'], + ['interval scheduled job failed | id: test-id-10 | async reason'], ]); }); @@ -116,7 +116,7 @@ test('Can handle crash of a sync job', async () => { schedulerService.stop(); expect(getRecords()).toEqual([ - ['scheduled job failed | id: test-id-11 | Error: sync reason'], - ['scheduled job failed | id: test-id-11 | Error: sync reason'], + ['initial scheduled job failed | id: test-id-11 | Error: sync reason'], + ['interval scheduled job failed | id: test-id-11 | Error: sync reason'], ]); });