Skip to content

Commit 18b2c28

Browse files
committed
Add logging for cron job execution in LifecycleService
1 parent 6e86e40 commit 18b2c28

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/management/lifecycle/lifecycle.service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { IdentitiesCrudService } from '../identities/identities-crud.service';
1515
import { ConfigObjectIdentitiesDTO, ConfigObjectSchemaDTO } from './_dto/config.dto';
1616
import { Lifecycle, LifecycleRefId } from './_schemas/lifecycle.schema';
1717
import { ConfigService } from '@nestjs/config';
18+
import dayjs from 'dayjs';
1819

1920
interface LifecycleSource {
2021
[source: string]: Partial<ConfigObjectIdentitiesDTO>[];
@@ -85,6 +86,14 @@ export class LifecycleService extends AbstractServiceSchema implements OnApplica
8586
const job = new CronJob(cronExpression, this.handleCron.bind(this, { lifecycleRules }));
8687
this.schedulerRegistry.addCronJob(`lifecycle-trigger`, job);
8788
this.logger.warn(`Lifecycle trigger cron job scheduled with expression: <${cronExpression}>`);
89+
90+
job.addCallback(async (): Promise<void> => {
91+
const now = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss');
92+
this.logger.debug(`Lifecycle trigger cron job executed at <${now}> !`);
93+
94+
const nextDate = dayjs(job.nextDate().toJSDate()).format('YYYY-MM-DD HH:mm:ss');
95+
this.logger.verbose(`Next execution at <${nextDate}>`);
96+
});
8897
job.start();
8998

9099
this.logger.log('LifecycleService bootstraped');

0 commit comments

Comments
 (0)