From 226f7febc05b1c5a18531855f8ab56d97810f992 Mon Sep 17 00:00:00 2001 From: scetron Date: Thu, 9 Nov 2023 13:33:28 -0500 Subject: [PATCH 1/3] update to run job after transaction commit --- nautobot_device_onboarding/worker.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nautobot_device_onboarding/worker.py b/nautobot_device_onboarding/worker.py index 266e6f58..cca5fd86 100644 --- a/nautobot_device_onboarding/worker.py +++ b/nautobot_device_onboarding/worker.py @@ -1,7 +1,9 @@ """Worker code for processing inbound OnboardingTasks.""" import logging +from django.db import transaction from django.core.exceptions import ValidationError + from prometheus_client import Summary from nautobot.dcim.models import Device @@ -132,7 +134,10 @@ def onboard_device(task_id, credentials): # pylint: disable=too-many-statements def enqueue_onboarding_task(task_id, credentials): """Detect worker type and enqueue task.""" if CELERY_WORKER: - onboard_device_worker.delay(task_id, credentials.nautobot_serialize()) # pylint: disable=no-member + # on commit + transaction.on_commit( + lambda: onboard_device_worker.delay(task_id, credentials.nautobot_serialize()) + ) if not CELERY_WORKER: get_queue("default").enqueue( # pylint: disable=used-before-assignment From 480c852c721e90ddd674cf41cca2ebacbb77c50e Mon Sep 17 00:00:00 2001 From: scetron Date: Thu, 9 Nov 2023 13:39:23 -0500 Subject: [PATCH 2/3] lint --- nautobot_device_onboarding/worker.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nautobot_device_onboarding/worker.py b/nautobot_device_onboarding/worker.py index cca5fd86..84356ae0 100644 --- a/nautobot_device_onboarding/worker.py +++ b/nautobot_device_onboarding/worker.py @@ -135,9 +135,7 @@ def enqueue_onboarding_task(task_id, credentials): """Detect worker type and enqueue task.""" if CELERY_WORKER: # on commit - transaction.on_commit( - lambda: onboard_device_worker.delay(task_id, credentials.nautobot_serialize()) - ) + transaction.on_commit(lambda: onboard_device_worker.delay(task_id, credentials.nautobot_serialize())) if not CELERY_WORKER: get_queue("default").enqueue( # pylint: disable=used-before-assignment From bd98fcd71f64ec01a520a62c86c7a68e3c658ef0 Mon Sep 17 00:00:00 2001 From: scetron Date: Fri, 10 Nov 2023 11:25:27 -0500 Subject: [PATCH 3/3] lint --- nautobot_device_onboarding/worker.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nautobot_device_onboarding/worker.py b/nautobot_device_onboarding/worker.py index 84356ae0..67a74b0e 100644 --- a/nautobot_device_onboarding/worker.py +++ b/nautobot_device_onboarding/worker.py @@ -135,7 +135,9 @@ def enqueue_onboarding_task(task_id, credentials): """Detect worker type and enqueue task.""" if CELERY_WORKER: # on commit - transaction.on_commit(lambda: onboard_device_worker.delay(task_id, credentials.nautobot_serialize())) + transaction.on_commit( + lambda: onboard_device_worker.delay(task_id, credentials.nautobot_serialize()) # pylint: disable=no-member + ) if not CELERY_WORKER: get_queue("default").enqueue( # pylint: disable=used-before-assignment