Skip to content

Commit ce81064

Browse files
committed
Make database use more explicit
1 parent 521c7c9 commit ce81064

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/task_processor/processor.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ def run_recurring_tasks(database: str) -> list[RecurringTaskRun]:
8080
# This is necessary to ensure that old instances of the task processor,
8181
# which may still be running during deployment, do not remove tasks added by new instances.
8282
# Reference: https://github.com/Flagsmith/flagsmith/issues/2551
83-
if (
84-
timezone.now() - task.created_at
85-
) > UNREGISTERED_RECURRING_TASK_GRACE_PERIOD:
86-
task.delete()
83+
task_age = timezone.now() - task.created_at
84+
if task_age > UNREGISTERED_RECURRING_TASK_GRACE_PERIOD:
85+
task.delete(using=database)
8786
continue
8887

8988
if task.should_execute:
@@ -95,10 +94,13 @@ def run_recurring_tasks(database: str) -> list[RecurringTaskRun]:
9594

9695
# update all tasks that were not deleted
9796
to_update = [task for task in tasks if task.id]
98-
RecurringTask.objects.bulk_update(to_update, fields=["is_locked", "locked_at"])
97+
RecurringTask.objects.using(database).bulk_update(
98+
to_update,
99+
fields=["is_locked", "locked_at"],
100+
)
99101

100102
if task_runs:
101-
RecurringTaskRun.objects.bulk_create(task_runs)
103+
RecurringTaskRun.objects.using(database).bulk_create(task_runs)
102104
logger.debug(f"Finished running {len(task_runs)} recurring task(s)")
103105

104106
return task_runs

0 commit comments

Comments
 (0)