Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does enqueue_at support timezones ? #101

Open
asennoussi opened this issue Nov 20, 2015 · 5 comments
Open

Does enqueue_at support timezones ? #101

asennoussi opened this issue Nov 20, 2015 · 5 comments

Comments

@asennoussi
Copy link

I want to enqueue a job at California timezone.
Will it work or will it ignore the timezone and execute at django's defined timezone ?

Thanks

@johnseekins
Copy link

If you look at the documentation, you see mentions of UTC time all over, but in particular:
scheduler.enqueue_at(datetime(2020, 1, 1), func) # Date time should be in UTC

So the answer is, use UTC.

@asennoussi
Copy link
Author

Maybe it'd be a nice feature for Rq-scheduler to care about the timezone and localize the time scheduled

@selwin
Copy link
Contributor

selwin commented Nov 21, 2015

The reason why we don't handle timezones is because we need to depend on external packages such as pytz which has quite a large footprint.

I think it should be we should be able to convert timezone aware datetimes into UTC but I don't have the time to look too deeply about this. If you know how to do this, PR is welcome :)

@ghost
Copy link

ghost commented Apr 7, 2016

Since 0.6.0 rq-scheduler user croniter, which use dateutil, so setting timezone can be done like this:

from datetime import datetime
from dateutil.tz import gettz
tz = "US/Pacific"
datetime(2020, 1, 1 tzinfo=gettz(tz)).astimezone(gettz("UTC"))
# datetime.datetime(2020, 1, 1, 8, 0, tzinfo=tzwin('UTC'))

For example, to support timezones in cron jobs, default get_next_scheduled_time can be replaced with something like this:

from datetime import datetime
from dateutil.tz import gettz

def get_next_scheduled_time_with_tz(cron_string, tz=None):
    tz = "UTC" if tz else tz
    itr = croniter.croniter(cron_string, datetime.now(gettz(tz)))
    return itr.get_next(datetime).astimezone(gettz("UTC"))

And tz attribute can be stored in job's meta property.

@simone6021
Copy link

simone6021 commented Jan 10, 2019

+1 for this, please 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants