У меня есть рабочий, который выполняет задачи для работы с APScheduler. Он работает отлично в первый день, а затем он падает при попытке получить следующие задания. Могу ли я повторить попытку после такого исключения? Или лучше предотвратить это?APScheduler python crash при попытке получить работу с jobstore
Вот код планировщика:
__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:%[email protected]%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,)]