node.js - 如何在上午 12:00 使用 NestJS 为多个国家/地区编写调度程序(在所有时区都相同)?
问题描述
我有一个调度程序,它必须在印度时区的上午 12:00 和新加坡时区的上午 12:00 运行。我能够为印度用户编写一个 cron 作业,但是如何在新加坡凌晨 12:00 触发相同的作业?
解决方案
如果使用这种方法,只需要编写一次代码,并从@Cron() 修饰的两个函数中调用它
服务.ts
@Injectable()
export class Service {
@Cron('* * 0 * * *', {
timeZone: 'Asia/Tehran', // use this website: https://momentjs.com/timezone/
})
async iran() {
this.yourFunction();
}
@Cron('* * 0 * * *', {
timeZone: 'Asia/Tokyo',
})
async japan() {
this.yourFunction();
}
async yourFunction() {
// write the schedule only one time
}
}
推荐阅读
- python - 在pyserial上清除串口的更快方法
- php - 找不到类“照亮\支持\外墙\存储”
- r - 计算非空白列的数量并分配给个别受访者
- azure - AppService 访问限制和来自 Release Pipelines 的访问
- python - 是否有一个 Pandas 相当于 Excel 的“文本到列”,使用可移动分隔符?
- python - 使用 Python 在 Raspberry 中记录文件错误
- javascript - 如何从我的包代码中导入航点
- string - MoarVM 中的字符串和链
- php - 在符号链接部署中启用 Opcache 文件缓存时导致段错误的原因是什么?
- ubuntu - 奇点/ubuntu:如何使用主机正宗代理