mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
Introduce pre_sync & post_sync signals
This commit is contained in:
parent
ee378cd0aa
commit
0613571002
@ -20,6 +20,7 @@ from utilities.files import sha256_hash
|
||||
from utilities.querysets import RestrictedQuerySet
|
||||
from ..choices import *
|
||||
from ..exceptions import SyncError
|
||||
from ..signals import post_sync, pre_sync
|
||||
|
||||
__all__ = (
|
||||
'DataSource',
|
||||
@ -137,6 +138,9 @@ class DataSource(PrimaryModel):
|
||||
if not self.ready_for_sync:
|
||||
raise SyncError(f"Cannot initiate sync; data source not ready/enabled")
|
||||
|
||||
# Emit the pre_sync signal
|
||||
pre_sync.send(sender=self.__class__, instance=self)
|
||||
|
||||
self.status = DataSourceStatusChoices.SYNCING
|
||||
DataSource.objects.filter(pk=self.pk).update(status=self.status)
|
||||
|
||||
@ -188,6 +192,9 @@ class DataSource(PrimaryModel):
|
||||
self.last_synced = timezone.now()
|
||||
DataSource.objects.filter(pk=self.pk).update(status=self.status, last_synced=self.last_synced)
|
||||
|
||||
# Emit the post_sync signal
|
||||
post_sync.send(sender=self.__class__, instance=self)
|
||||
|
||||
def _walk(self, root):
|
||||
"""
|
||||
Return a set of all non-excluded files within the root path.
|
||||
|
10
netbox/core/signals.py
Normal file
10
netbox/core/signals.py
Normal file
@ -0,0 +1,10 @@
|
||||
import django.dispatch
|
||||
|
||||
__all__ = (
|
||||
'post_sync',
|
||||
'pre_sync',
|
||||
)
|
||||
|
||||
# DataSource signals
|
||||
pre_sync = django.dispatch.Signal()
|
||||
post_sync = django.dispatch.Signal()
|
Loading…
Reference in New Issue
Block a user