APScheduler如何立即触发工作
我在Flask应用中有一个APScheduler,每隔一定的时间发送事件。
现在,我需要“刷新”的所有作业,其实刚开始他们 现在 如果他们不接触不上定义的时间间隔运行。
我试着先叫job.pause(),然后叫job.resume(),什么也没有,然后使用job。reschedule_job(…)会触发它,但也会更改间隔…我不想要。
我的实际代码如下:
cron = GeventScheduler(daemon=True)# Explicitly kick off the background thread
cron.start()
cron.add_job(_job_time, 'interval', seconds=5, id='_job_time')
cron.add_job(_job_forecast, 'interval', hours=1, id='_job_forecast_01')
@app.route("/refresh")
def refresh():
refreshed = []
for job in cron.get_jobs():
job.pause()
job.resume()
refreshed.append(job.id)
return json.dumps( {'number': len(cron.get_jobs()), 'list': refreshed} )
回答:
您也可以直接运行job函数。
for job in cron.get_jobs(): job.func()
如果将args或kwargs传递到函数中,则必须将其从job.args
and /
or中拉出job.kwargs
。参见apscheduler.job.Job
以上是 APScheduler如何立即触发工作 的全部内容, 来源链接: utcz.com/qa/419994.html