js简单使用定时任务

2023-09-23 晚上后端 20 次浏览暂无评论
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();

目录

ICP备案号:鲁ICP备2020040322号