Skip to content

Instantly share code, notes, and snippets.

@quietin
Created January 8, 2016 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quietin/d9436fc009eff113dc7f to your computer and use it in GitHub Desktop.
Save quietin/d9436fc009eff113dc7f to your computer and use it in GitHub Desktop.
a simple scheduler class
# coding: utf8
from pytz import timezone
from apscheduler.schedulers.blocking import BlockingScheduler
class Schedule(object):
_default_conf = dict(
trigger="cron", hour='03', minute='00'
)
_default_sche = BlockingScheduler({
'apscheduler.executors.default': {
'class': 'apscheduler.executors.pool:ThreadPoolExecutor',
'max_workers': '4'
},
'apscheduler.executors.processpool': {
'type': 'processpool',
'max_workers': '4'
},
'apscheduler.job_defaults.coalesce': 'false',
'apscheduler.job_defaults.max_instances': '16',
'timezone': timezone('Asia/Shanghai'),
})
def __init__(self, scheduler=_default_sche):
self.scheduler = scheduler
def run(self):
self.scheduler.start()
def add_job(self, func, conf=_default_conf, **kwargs):
kwargs.update(conf)
self.scheduler.add_job(func, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment