mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 10:58:37 -06:00
Enqueue a SyncDataSourceJob when needed after saving a DataSource
This commit is contained in:
parent
5e9172ce97
commit
91d8cb596e
@ -10,14 +10,13 @@ from django_prometheus.models import model_deletes, model_inserts, model_updates
|
||||
|
||||
from core.choices import ObjectChangeActionChoices
|
||||
from core.events import *
|
||||
from core.models import ObjectChange
|
||||
from extras.events import enqueue_event
|
||||
from extras.utils import run_validators
|
||||
from netbox.config import get_config
|
||||
from netbox.context import current_request, events_queue
|
||||
from netbox.models.features import ChangeLoggingMixin
|
||||
from utilities.exceptions import AbortRequest
|
||||
from .models import ConfigRevision
|
||||
from .models import ConfigRevision, DataSource, ObjectChange
|
||||
|
||||
__all__ = (
|
||||
'clear_events',
|
||||
@ -182,6 +181,20 @@ def clear_events_queue(sender, **kwargs):
|
||||
# DataSource handlers
|
||||
#
|
||||
|
||||
@receiver(post_save, sender=DataSource)
|
||||
def enqueue_sync_job(instance, **kwargs):
|
||||
"""
|
||||
When a DataSource is saved, check its sync_interval and enqueue a sync job if appropriate.
|
||||
"""
|
||||
from .jobs import SyncDataSourceJob
|
||||
|
||||
if instance.sync_interval:
|
||||
SyncDataSourceJob.enqueue_once(instance, interval=instance.sync_interval)
|
||||
else:
|
||||
# Delete any previously scheduled recurring jobs for this DataSource
|
||||
SyncDataSourceJob.get_jobs(instance).filter(sync_interval__isnull=False).delete()
|
||||
|
||||
|
||||
@receiver(post_sync)
|
||||
def auto_sync(instance, **kwargs):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user