我们使用 Apscheduler 3.3.1 中的 JobStores 使用 Mysql 来存储调度程序作业。 作业正在作为 blob 存储在数据库中,但 apscheduler 没有运行该作业。 Apscheduler 显示正在添加作业,但没有给出任何错误或任何指示...... 我添加的工作:
运行.py
jobstores =
{
'default': SQLAlchemyJobStore(url="mysql+pymysql://root:XXXXX@localhost/XXXX",tablename='apscheduler_jobs')
}
executors =
{
'default': ThreadPoolExecutor(20),
'processpool': ProcessPoolExecutor(5)
}
job_defaults =
{
'coalesce': False,
'max_instances': 3
}
scheduler = BackgroundScheduler(jobstores=jobstores,
executors=executors,
job_defaults=job_defaults)
scheduler.start()
if __name__=="__main__":
app.run()
add_job.py
from app.run import app
def my_decorator():
# phase status written in file
new_path = '/home/admin1/testing.txt'
new_days = open(new_path, 'a')
new_days.write("teting added\n")
new_days.close()
@app.route(/add_job)
def add_cron_job(self,scheduler):
# add delay in app.config method then access here
# app.config['email_campaing_delay']
job_id = str(uuid.uuid1())
job = scheduler.add_job(my_decorator,
trigger='cron',
args=[],
id=job_id,
# max_instances=1,
second='*/5',
jobstore='default')
print('added job in the background scheduler------', job.id)
scheduler.print_jobs()
try:
scheduler.start()
print('scheduler started')
except Exception as e:
print('Exception from add_cron_job is =====', e)
我也面临着同样的问题。在我们的应用程序中,重新启动应用程序就是从调度程序表中重新一一挑选所有作业。
我们正在遵循一个临时解决方案来从 Kubernetes 安排一个作业来到达应用程序的端点,这将触发调度程序功能。这只是我们正在遵循的临时修复方案。
找了好久都找不到解决办法。如果有人能找到解决方案,请在此处发帖帮助我们。