From 51b7c0d919fdbc3875248df1f5f3fee69bb25ea4 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sat, 4 Feb 2023 11:46:38 -0700 Subject: [PATCH] Undo one connection per transition --- stator/runner.py | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/stator/runner.py b/stator/runner.py index 7162380..5525be7 100644 --- a/stator/runner.py +++ b/stator/runner.py @@ -6,7 +6,7 @@ import time import traceback import uuid -from asgiref.sync import ThreadSensitiveContext, async_to_sync, sync_to_async +from asgiref.sync import async_to_sync, sync_to_async from django.conf import settings from django.utils import timezone @@ -210,26 +210,25 @@ class StatorRunner: Wrapper for atransition_attempt with fallback error handling """ task_name = f"stator.run_transition:{instance._meta.label_lower}#{{id}} from {instance.state}" - async with ThreadSensitiveContext(): - with sentry.start_transaction(op="task", name=task_name): - sentry.set_context( - "instance", - { - "model": instance._meta.label_lower, - "pk": instance.pk, - "state": instance.state, - "state_age": instance.state_age, - }, - ) + with sentry.start_transaction(op="task", name=task_name): + sentry.set_context( + "instance", + { + "model": instance._meta.label_lower, + "pk": instance.pk, + "state": instance.state, + "state_age": instance.state_age, + }, + ) - try: - print( - f"Attempting transition on {instance._meta.label_lower}#{instance.pk} from state {instance.state}" - ) - await instance.atransition_attempt() - except BaseException as e: - await exceptions.acapture_exception(e) - traceback.print_exc() + try: + print( + f"Attempting transition on {instance._meta.label_lower}#{instance.pk} from state {instance.state}" + ) + await instance.atransition_attempt() + except BaseException as e: + await exceptions.acapture_exception(e) + traceback.print_exc() def remove_completed_tasks(self): """