3

I have a scheduler that has to run on 12:00 AM of Indian time zone and 12:00 AM of Singapore timezone. I was able to write a cron job for Indian users, But how to trigger the same in Singapore at 12:00 AM?

Balaji Venkatraman
  • 1,228
  • 12
  • 19

2 Answers2

10

if you use this method, only one time you need to write the code, and call it from two functions that decorated by @Cron()

service.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
  }
}
ehsan mandegar
  • 319
  • 1
  • 8
0

I think easily use for example 9:30 PM (UTC+08:00(Singapore) - UTC+05:30(India)) AM instead of 12:00 AM

ehsan mandegar
  • 319
  • 1
  • 8