feat(schedules): add next invocation logging for event-watch job
- Import 'dayjs' to format timestamps for better readability. - Store the scheduled job instance in a private field to access next execution time. - Update the 'start' method to log the job name and the precise next run time. - Update 'watchEvents' method with a debug log for the next invocation. This improves observability by showing exactly when the scheduled task is expected to run next, rather than just the schedule definition.
This commit is contained in:
parent
8dff4009bf
commit
0a1c424798
@ -6,11 +6,16 @@ import { diffArrays } from '../utils/common';
|
||||
import { sendNotification } from '../utils/firebase-admin';
|
||||
import { prisma } from '../prisma/db';
|
||||
import type { Schedule } from './schedule';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
export class EventWatchSchedule implements Schedule {
|
||||
|
||||
#job?: nodeSchedule.Job;
|
||||
|
||||
constructor() {}
|
||||
|
||||
async watchEvents() {
|
||||
console.debug('nextStartTime: %s', dayjs(this.#job?.nextInvocation()).format('YYYY-MM-DD HH:mm:ss'));
|
||||
const events = await EventSubscribeService.getAllEvents();
|
||||
events.forEach((e) => this.diffEvent(e));
|
||||
}
|
||||
@ -56,10 +61,11 @@ export class EventWatchSchedule implements Schedule {
|
||||
await Promise.all(tokens.map(token => sendNotification(token, { title, body, url })));
|
||||
}
|
||||
start() {
|
||||
const schedule = nodeSchedule.scheduleJob('event-watch', {
|
||||
const job = nodeSchedule.scheduleJob('event-watch', {
|
||||
minute: [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55],
|
||||
hour: new nodeSchedule.Range(7, 23),
|
||||
}, () => this.watchEvents());
|
||||
console.debug('Start schedule:', schedule.name);
|
||||
this.#job = job;
|
||||
console.debug('Start schedule: %s, next run at %s', job.name, dayjs(job.nextInvocation()).format('YYYY-MM-DD HH:mm:ss'));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user