Question regarding interval jobs with a scheduler using the UTC timezone

320 views
Skip to first unread message

Andreas Levers

unread,
Sep 24, 2014, 10:06:33 AM9/24/14
to apsch...@googlegroups.com
Hello everyone,

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.

Example:

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!
Thanks,
Andreas

Alex Grönholm

unread,
Sep 24, 2014, 9:41:36 PM9/24/14
to apsch...@googlegroups.com
24.09.2014, 17:06, Andreas Levers kirjoitti:
Hello everyone,

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.

Would you mind creating an issue on Bitbucket for this?
Example:

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!
Thanks,
Andreas
--
You received this message because you are subscribed to the Google Groups "APScheduler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andreas Levers

unread,
Sep 25, 2014, 2:43:44 AM9/25/14
to apsch...@googlegroups.com
Am Donnerstag, 25. September 2014 03:41:36 UTC+2 schrieb Alex Grönholm:
24.09.2014, 17:06, Andreas Levers kirjoitti:
Would you mind creating an issue on Bitbucket for this?

Thanks. I have created the issue:

This is the first time I've filed a bug report; please bear with me if the description or sample are incomplete.
Reply all
Reply to author
Forward
0 new messages