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:
@@ -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)
|
||||
|
@@ -3,6 +3,7 @@ from django.shortcuts import get_object_or_404, redirect
|
||||
|
||||
from netbox.views import generic
|
||||
from netbox.views.generic.base import BaseObjectView
|
||||
from utilities.rqworker import get_queue_for_model, get_workers_for_queue
|
||||
from utilities.utils import count_related
|
||||
from utilities.views import register_model_view
|
||||
from . import filtersets, forms, tables
|
||||
@@ -31,7 +32,11 @@ class DataSourceView(generic.ObjectView):
|
||||
(DataFile.objects.restrict(request.user, 'view').filter(source=instance), 'source_id'),
|
||||
)
|
||||
|
||||
queue_name = get_queue_for_model(DataSource)
|
||||
sync_enabled = bool(get_workers_for_queue(queue_name))
|
||||
|
||||
return {
|
||||
'sync_enabled': sync_enabled,
|
||||
'related_models': related_models,
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user