Undo one connection per transition

pull/497/head
Andrew Godwin 2023-02-04 11:46:38 -07:00
rodzic f7948a55bf
commit 51b7c0d919
1 zmienionych plików z 19 dodań i 20 usunięć

Wyświetl plik

@ -6,7 +6,7 @@ import time
import traceback import traceback
import uuid 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.conf import settings
from django.utils import timezone from django.utils import timezone
@ -210,26 +210,25 @@ class StatorRunner:
Wrapper for atransition_attempt with fallback error handling Wrapper for atransition_attempt with fallback error handling
""" """
task_name = f"stator.run_transition:{instance._meta.label_lower}#{{id}} from {instance.state}" 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):
with sentry.start_transaction(op="task", name=task_name): sentry.set_context(
sentry.set_context( "instance",
"instance", {
{ "model": instance._meta.label_lower,
"model": instance._meta.label_lower, "pk": instance.pk,
"pk": instance.pk, "state": instance.state,
"state": instance.state, "state_age": instance.state_age,
"state_age": instance.state_age, },
}, )
)
try: try:
print( print(
f"Attempting transition on {instance._meta.label_lower}#{instance.pk} from state {instance.state}" f"Attempting transition on {instance._meta.label_lower}#{instance.pk} from state {instance.state}"
) )
await instance.atransition_attempt() await instance.atransition_attempt()
except BaseException as e: except BaseException as e:
await exceptions.acapture_exception(e) await exceptions.acapture_exception(e)
traceback.print_exc() traceback.print_exc()
def remove_completed_tasks(self): def remove_completed_tasks(self):
""" """