Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass UTC timezone for APScheduler 3.0?

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()
like image 382
mishap_n Avatar asked Sep 10 '15 00:09

mishap_n


People also ask

What is Max_instances in APScheduler?

The max_instances only tells you how many concurrent jobs you can have. APScheduler has three types of triggers: date interval cron. interval and cron repeat forever, date is a one-shot on a given date.

How does APScheduler work?

APScheduler provides many different ways to configure the scheduler. You can use a configuration dictionary or you can pass in the options as keyword arguments. You can also instantiate the scheduler first, add jobs and configure the scheduler afterwards. This way you get maximum flexibility for any environment.

How do I stop APScheduler?

It only stops when you type Ctrl-C from your keyboard or send SIGINT to the process. This scheduler is intended to be used when APScheduler is the only task running in the process. It blocks all other code from running unless the others are running in separated threads.


1 Answers

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

like image 54
Dark Knight Avatar answered Sep 20 '22 22:09

Dark Knight