Skip to content

Commit

Permalink
Fixes #23: Branch job runners for sync & merge should suppress AbortT…
Browse files Browse the repository at this point in the history
…ransaction exceptions
  • Loading branch information
jeremystretch committed Aug 8, 2024
1 parent aa7f933 commit 6a585ea
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions netbox_branching/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from core.signals import handle_changed_object, handle_deleted_object
from netbox.jobs import JobRunner
from utilities.exceptions import AbortTransaction
from .utilities import ListHandler

__all__ = (
Expand Down Expand Up @@ -77,6 +78,8 @@ def run(self, commit=True, *args, **kwargs):
try:
branch = self.job.object
branch.sync(user=self.job.user, commit=commit)
except AbortTransaction:
logger.info("Dry run completed; rolling back changes")
except Exception as e:
# TODO: Can JobRunner be extended to handle this more cleanly?
# Ensure that signal handlers are reconnected
Expand All @@ -101,5 +104,8 @@ def run(self, commit=True, *args, **kwargs):
logger.addHandler(ListHandler(queue=get_job_log(self.job)))

# Merge the Branch
branch = self.job.object
branch.merge(user=self.job.user, commit=commit)
try:
branch = self.job.object
branch.merge(user=self.job.user, commit=commit)
except AbortTransaction:
logger.info("Dry run completed; rolling back changes")

0 comments on commit 6a585ea

Please sign in to comment.