Undo one connection per transition

This commit is contained in:
Andrew Godwin 2023-02-04 11:46:38 -07:00
parent f7948a55bf
commit 51b7c0d919

View file

@ -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):
""" """