Bal*_*man 3 node.js express nestjs nestjs-config
我有一个调度程序,必须在印度时区的上午 12:00 和新加坡时区的上午 12:00 运行。我能够为印度用户编写一个 cron 作业,但如何在新加坡凌晨 12:00 触发同样的任务?
小智 10
如果使用这种方法,只需要编写一次代码,并从两个用@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
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3679 次 |
最近记录: |