允许异步和延迟任务调度和管理的金字塔插件。
pyramid_scheduler的Python项目详细描述
tl;dr
安装:
$ pip install pyramid-scheduler使用:
# ini file settings:# [app:main]# scheduler.combined = true | false ## should execution be in-process?# scheduler.queues = jobs ## space-separated list of queues# scheduler.broker.url = %(dburl)s ## the URL used for kombu messaging# ## other optional settings:# ## scheduler.housekeeping# ## scheduler.housekeeping.append# ## scheduler.jobstore.default.class# ## scheduler.misfire_grace_time# enabling the plugin adds a `scheduler` attribute to the registrydefmain(global_config,**settings):# ... (the usual pyramid startup calls) ...config.include('pyramid_scheduler)# create an asynchronous taskdefslow_process(name,id):# ...a slow asynchronous job...defhandle_request_quickly(request):request.registry.scheduler.add_async_job(slow_process,args=('my-first-arg',2))# schedule a deferred task for one hour from nowdefdelayed_process():# ...something that should happen later...defhandle_request_now(request):importtimerequest.registry.scheduler.add_date_job(delayed_process,time.time()+3600)# do something every 10 minutesdefinterval_process(reason=None):# ...gets executed every 10 minutes with an optional reason...defhandle_request_often(request):request.registry.scheduler.add_date_job(interval_process,minutes=10)