django-q2 icon indicating copy to clipboard operation
django-q2 copied to clipboard

Timezone definition in the scheduled task

Open ThomasDeudon opened this issue 9 months ago • 1 comments

Hello,

First, thank you for the project, very helpful.

I am trying to have scheduled task in a CRON setup to have a timezone attached.

Example : "30 8 * * 1" could be with GMT or with NYK timezone and would be understood (and not looking only at the cluster timezone), is there a way to do this properly ?

The only solution I am seeing is to have a queue per timezone and having this forced to a specific queue (But this seems sub optimal to say the least), any suggestions ?

ThomasDeudon avatar May 14 '24 18:05 ThomasDeudon

Hmm.. Another solution would be to create 4 schedules. One for each timezone and then another one for each for daylight savings. Then in the task check which one needs to run based on the time.

Still not ideal, but might be doable for now as a workaround.

GDay avatar May 14 '24 19:05 GDay

Sorry my question was not clear so my understanding of your answer is not certain.

I want to be able to say for example 2 schedules :

  1. "30 8 * * 1" with "GMT" so that it runs at 8:30 GMT on the monday
  2. "30 9 * * 1" with "NYC" so that it runs at 9:30 NYC on the monday

This is doable with only one queue initialized with a timezone of SGT for example ?

ThomasDeudon avatar May 14 '24 22:05 ThomasDeudon

This is doable with only one queue initialized with a timezone of SGT for example ?

Yes, but there are two caveats:

I think SGT doesn't have daylight savings, that's good.

There is daylight savings for GMT and NYC and the days they switch will be different from each other.

So what you would need to do is create 4 schedules:

  • cron for GMT not using daylight savings (change the 8 value to match the hour in GMT compared to SGT time)
  • cron for GMT using daylight savings (change the 8 value to match the hour in GMT compared to SGT time)
  • cron for NYC not using daylight savings (change the 9 value to match the hour in NYC compared to SGT time)
  • cron for NYC using daylight savings (change the 9 value to match the hour in NYC compared to SGT time)

Then when running the function, check what the current hour is in the timezone and only continue if it is the hour you want it to run.

It's a bit of workaround, but it should work fine.

Does that make sense?

GDay avatar May 16 '24 02:05 GDay

thanks for the answer. Unfortunately the different timezone I want to offer have different times for DST and it would be difficult to keep track. I think I will go through the multiple clusters with different timezone solution

ThomasDeudon avatar May 16 '24 06:05 ThomasDeudon

The above worked.

ThomasDeudon avatar May 29 '24 10:05 ThomasDeudon