gpt4 book ai didi

python - 尝试从 jobstore 获取作业时 APScheduler python 崩溃

转载 作者:行者123 更新时间:2023-11-29 19:27:22 29 4
gpt4 key购买 nike

我有工作人员使用 APScheduler 执行任务。它第一天运行完美,然后在尝试获取下一个作业时崩溃了。在出现此类异常后我可以做一些重试吗?或者更好地防止这种情况发生?

这是调度程序代码:

__jbs_name = 'default1'
__jbs_tn = 'Framework_Jobs'
__jbs_class = 'apscheduler.jobstore.%s.class' % __jbs_name
__jbs_url = 'apscheduler.jobstore.%s.url' % __jbs_name
__jbs_table = 'apscheduler.jobstore.%s.tablename' % __jbs_name
__jbs_sqlalchemy = 'apscheduler.jobstores.sqlalchemy_store:SQLAlchemyJobStore'
__db_username = '******'
__db_password = '*************'
__db_location = 'localhost'
__db_dbname = 'djangoTest'
__db_url = 'mysql://%s:%s@%s/%s' % \
(__db_username, __db_password,
__db_location, __db_dbname)
# APScheduler (preferred) default configuration
_g_aps_default_sql_config = {
'apscheduler.misfire_grace_time': 15 * 60,
'apscheduler.coalesce': True,
'apscheduler.daemonic': True,
'apscheduler.standalone': True,
__jbs_class: __jbs_sqlalchemy,
__jbs_url: __db_url,
__jbs_table: __jbs_tn
}

sched = BackgroundScheduler()
sched.configure(gconfig=_g_aps_default_sql_config)

这是我的日志:

2017-02-04 05:42:00;DEBUG;Looking for jobs to run
Exception in thread APScheduler:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/local/lib/python2.7/dist-packages/apscheduler/schedulers/blocking.py", line 30, in _main_loop
wait_seconds = self._process_jobs()
File "/usr/local/lib/python2.7/dist-packages/apscheduler/schedulers/base.py", line 924, in _process_jobs
for job in jobstore.get_due_jobs(now):
File "/usr/local/lib/python2.7/dist-packages/apscheduler/jobstores/sqlalchemy.py", line 71, in get_due_jobs
return self._get_jobs(self.jobs_t.c.next_run_time <= timestamp)
File "/usr/local/lib/python2.7/dist-packages/apscheduler/jobstores/sqlalchemy.py", line 133, in _get_jobs
for row in self.engine.execute(selectable):
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1991, in execute
return connection.execute(statement, *multiparams, **params)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 914, in execute
return meth(self, multiparams, params)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1010, in _execute_clauseelement
compiled_sql, distilled_params
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
context)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
exc_info
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 202, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
context)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 450, in do_execute
cursor.execute(statement, parameters)
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (_mysql_exceptions.OperationalError) (2006, 'MySQL server has gone away') [SQL: u'SELECT apscheduler_jobs.id, apscheduler_jobs.job_state \nFROM apscheduler_jobs \nWHERE apscheduler_jobs.next_run_time <= %s ORDER BY apsc
heduler_jobs.next_run_time'] [parameters: (1486179720.090187,)]

最佳答案

我运行的是 3.2 版本,此功能出现在 3.3 版本中

最新的至少可以过一段时间重试(jobstore_retry_interval设置默认为10(秒))。

除此之外,我不建议出于任何目的使用 MySQL。如果您可以切换的话,我推荐使用 PostgreSQL。

感谢亚历克斯的回答: https://groups.google.com/forum/#!topic/apscheduler/SplRuAB9l78

关于python - 尝试从 jobstore 获取作业时 APScheduler python 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42043779/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com