js简单使用定时任务
const job = new CronJob(`0 */1 * * * *`, async () => {
const now = dayjs().toDate();
const oneMinuteAgo = dayjs().subtract(5, 'minute').toDate();
const messages = await this.pushMessageRepository.findBy({
status: 1,
pushTime: Between(oneMinuteAgo, now),
});
messages.forEach((item) => {
this.push(item.id);
});
});
this.schedulerRegistry.addCronJob(`cron-pushMessage`, job);
job.start();