Fix: Issue where cron would end up in nested transaction blocks and unable to escape.
This commit is contained in:
parent
94309ed257
commit
46a392ba31
1 changed files with 45 additions and 43 deletions
|
@ -87,8 +87,9 @@ def _run_tasks(db_session_factory: scoped_session):
|
|||
running task does not lock the entire table for its entire run, which would
|
||||
for example, prevent any statistics about status from being gathered.
|
||||
'''
|
||||
db: Session = db_session_factory()
|
||||
|
||||
db: Session
|
||||
with db_session_factory() as db:
|
||||
with _acquire_lock_exclusive(db, RepeatableTask.__tablename__):
|
||||
now: datetime = datetime.now(tz=timezone.utc)
|
||||
|
||||
|
@ -116,10 +117,11 @@ def _run_tasks(db_session_factory: scoped_session):
|
|||
task.run_time_last = now
|
||||
task.run_state_enum = ScheduledTaskState.RUNNING
|
||||
|
||||
# This *must* happen before we start doing db queries, including sqlalchemy db queries
|
||||
db.begin()
|
||||
task_debug_identifier = f"(ID {task.id}:{task.label})"
|
||||
logging.info(f"Running task {task_debug_identifier}")
|
||||
|
||||
db.begin()
|
||||
run: RepeatableTaskRun = task.run(db, task.run_time_last_or_created_utc)
|
||||
|
||||
if run.exception:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue