mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-09 00:58:16 -06:00
Adding rq_queue_name to API and Views
This commit is contained in:
parent
3146a4889a
commit
b203c9d916
@ -1,6 +1,7 @@
|
||||
import uuid
|
||||
|
||||
import django_rq
|
||||
from rq.exceptions import NoSuchJobError
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||
from django.core.exceptions import ValidationError
|
||||
@ -152,10 +153,14 @@ class Job(models.Model):
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
super().delete(*args, **kwargs)
|
||||
|
||||
rq_queue_name = get_config().QUEUE_MAPPINGS.get(self.object_type.model, RQ_QUEUE_DEFAULT)
|
||||
queue = django_rq.get_queue(rq_queue_name)
|
||||
job = queue.fetch_job(str(self.job_id))
|
||||
job = None
|
||||
for check_queue in get_config().QUEUE_MAPPINGS:
|
||||
queue = django_rq.get_queue(check_queue)
|
||||
try:
|
||||
job = queue.fetch_job(str(self.job_id))
|
||||
break
|
||||
except NoSuchJobError:
|
||||
pass
|
||||
|
||||
if job:
|
||||
job.cancel()
|
||||
|
@ -261,6 +261,7 @@ class ScriptViewSet(ModelViewSet):
|
||||
request=copy_safe_request(request),
|
||||
commit=input_serializer.data['commit'],
|
||||
job_timeout=script.python_class.job_timeout,
|
||||
rq_queue_name=script.python_class.rq_queue_name,
|
||||
schedule_at=input_serializer.validated_data.get('schedule_at'),
|
||||
interval=input_serializer.validated_data.get('interval')
|
||||
)
|
||||
|
@ -1110,6 +1110,7 @@ class ScriptView(BaseScriptView):
|
||||
data=form.cleaned_data,
|
||||
request=copy_safe_request(request),
|
||||
job_timeout=script.python_class.job_timeout,
|
||||
rq_queue_name=script.python_class.rq_queue_name,
|
||||
commit=form.cleaned_data.pop('_commit')
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user