NestJS部署为Windows服务后短间隔Cron定时任务意外停止运行求助
NestJS部署为Windows服务后短间隔Cron定时任务意外停止运行求助
我现在碰到一个棘手的问题,想请各位帮忙分析下:
我有个NestJS应用部署在Windows Server上,是通过nssm把它安装成Windows服务来运行的。应用里用@nestjs/schedule实现了5个Cron定时任务:
- 1个每分钟执行一次
- 1个每5分钟执行一次
- 其余的分别是每10分钟、15分钟、1小时执行一次
但运行一段时间后发现,那两个短间隔的定时任务(1分钟和5分钟的)会意外停止触发,而且再也不会自动恢复,可长间隔的任务却能正常运行。更奇怪的是,Windows服务本身一直处于运行状态,应用日志里也完全找不到相关的报错信息。
下面是我5分钟定时任务的示例代码:
import { Cron } from '@nestjs/schedule'; import { Injectable, Logger } from '@nestjs/common'; @Injectable() export class TasksService { private readonly logger = new Logger(TasksService.name); @Cron('*/5 * * * *') async scheduledHandleCronOld() { this.logger.log('Old File Processing Job >> Starting scheduled handleCronOld...'); try { if (this.config.get('SFTP_FILE_FORMAT') === 'OLD') { await this.handleCronOld(null); } else { this.logger.log('Old File Processing Job >> Ended due to config is NEW File Format...'); } } catch (error) { this.logger.error(`Old File Processing Job >> Scheduler error: ${error.message}`); } } }
1分钟的定时任务逻辑和这个类似,都是先打日志、做配置判断、执行业务逻辑,异常也都做了捕获打日志,但就是会莫名停掉。
有没有大佬遇到过类似的情况?或者能给些排查方向的建议?
内容来源于stack exchange
相关产品推荐
相关产品推荐

