Skip to content

Commit

Permalink
fix: Stale connections after task processor errors (#4179)
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 authored Jun 18, 2024
1 parent 710ed87 commit 17782bd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 3 additions & 3 deletions api/task_processor/threads.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import time
import traceback
from threading import Thread

from django.db import close_old_connections
from django.utils import timezone

from task_processor.processor import run_recurring_tasks, run_tasks
Expand Down Expand Up @@ -42,8 +42,8 @@ def run_iteration(self) -> None:
# TODO: is this also what is causing tasks to get stuck as locked? Can we unlock
# tasks here?

logger.error("Received error retrieving tasks: %s.", e)
logger.debug(traceback.format_exc())
logger.error("Received error retrieving tasks: %s.", e, exc_info=e)
close_old_connections()

def stop(self):
self._stopped = True
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ def test_task_runner_is_resilient_to_errors(
task_runner.run_iteration()

# Then
assert len(caplog.records) == 2
assert len(caplog.records) == 1

assert caplog.records[0].levelno == logging.ERROR
assert (
caplog.records[0].message
== f"Received error retrieving tasks: {exception_message}."
)

assert caplog.records[1].levelno == logging.DEBUG
assert caplog.records[1].message.startswith("Traceback")

0 comments on commit 17782bd

Please sign in to comment.