9

Any Heroku folks on here? It seems their system will not execute things from APScheduler labeled as cron. FYI: I'm using the free package. Using this example, the interval will run, the cron will not. Has anyone else run into this?

EDIT: Its been suggested that I specify UTC I am unsure how to do that using add_job. Any takers? Because I know this isn't currently right:

from apscheduler.schedulers.blocking import BlockingScheduler
from pytz import utc

sched = BlockingScheduler(timezone=utc)

def grabit():
    print "This job is run every weekday"

def tick():
    print "every 5 minutes"

sched.add_job(grabit, 'cron', day_of_week='mon-fri', hour=0, minute=13, id="get_things", replace_existing=True)
sched.add_job(tick, 'interval', minutes=5)
sched.start()

3 Answers 3

19

You can pass the string like this:

sched = BlockingScheduler(timezone="Asia/Kolkata")

And find the string using thisL

from tzlocal import get_localzone
tz = get_localzone()
print(tz)

The object will contain the string

0

Update to dark Knight's solution:

from tzlocal import get_localzone
tz = get_localzone()
print(tz)

Output:

Asia/Kolkata
2
  • Hi Manoj, welcome to stackoverflow. It's not clear to me how this answers the question being asked. Could you please elaborate? Commented Jul 3, 2020 at 23:55
  • 2
    Thank you demented hedgehog for the warm welcome. I came across this and thought of adding an update, I found to the dark Knight's solution. Commented Jul 4, 2020 at 16:24
0

The question is asking about UTC timezone:

import datetime
from apscheduler.schedulers.blocking import BlockingScheduler

sched = BlockingScheduler(timezone=datetime.UTC)

def tick():
    print "every 5 minutes"

sched.add_job(tick, 'interval', minutes=5)
sched.start()

Use datatime's UTC is better because this is a builtin package. If you check args required by BaseScheduler, it accepts str|datetime.tzinfo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.