I recently started using APScheduler for recurring tasks using the interval trigger. When I changed the timezone to UTC I noticed that my jobs were not called until 2 hours had passed. This corresponds to the offset of my local timezone relative to UTC. Adding a next_run_time argument fixed this but I wonder if this is intended behavior, as cron-triggered jobs immediately execute without explicitly setting a next_run_time.
from pytz import utc
from datetime import datetime
from apscheduler.schedulers.background import BlockingScheduler as Scheduler
def test_1():
print "Foo"
def test_2():
print "Bar"
def test_3():
print "Baz"
scheduler = Scheduler(timezone=utc)
scheduler.add_job(test_1, trigger='interval', seconds=1)
scheduler.add_job(test_2, trigger='interval', seconds=1, next_run_time=datetime.utcnow())
scheduler.add_job(test_3, trigger='cron', year='*', month='*', day='*', week='*', day_of_week='*', hour='*', minute='*', second='*/1')
scheduler.start()
I am unsure if I missed something obvious. Any hints are appreciated!