1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

#11558: Disable sync button if RQ worker not running

This commit is contained in:
jeremystretch
2023-03-20 15:12:11 -04:00
parent 13d604d44e
commit 08bdb54cb4
6 changed files with 43 additions and 12 deletions

View File

@ -16,7 +16,6 @@ from django.utils.translation import gettext as _
from extras.models import JobResult
from netbox.models import PrimaryModel
from netbox.models.features import ChangeLoggingMixin
from netbox.registry import registry
from utilities.files import sha256_hash
from utilities.querysets import RestrictedQuerySet
@ -116,6 +115,7 @@ class DataSource(PrimaryModel):
"""
# Set the status to "syncing"
self.status = DataSourceStatusChoices.QUEUED
DataSource.objects.filter(pk=self.pk).update(status=self.status)
# Enqueue a sync job
job_result = JobResult.enqueue_job(
@ -137,8 +137,8 @@ class DataSource(PrimaryModel):
"""
Create/update/delete child DataFiles as necessary to synchronize with the remote source.
"""
if not self.ready_for_sync:
raise SyncError(f"Cannot initiate sync; data source not ready/enabled")
if self.status == DataSourceStatusChoices.SYNCING:
raise SyncError(f"Cannot initiate sync; syncing already in progress.")
# Emit the pre_sync signal
pre_sync.send(sender=self.__class__, instance=self)