Skip to content

Commit

Permalink
update to run job after transaction commit
Browse files Browse the repository at this point in the history
  • Loading branch information
scetron committed Nov 9, 2023
1 parent 3897b11 commit 226f7fe
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nautobot_device_onboarding/worker.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 226f7fe

Please sign in to comment.