Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Stale connections after task processor errors #4179

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Loading