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

Job Scheduling WIP

This commit is contained in:
kkthxbye-code
2022-09-23 06:45:40 +02:00
parent c8671ce8e8
commit cbb3378d10
7 changed files with 81 additions and 1 deletions

View File

@ -509,12 +509,18 @@ class JobResult(models.Model):
unique=True
)
objects = RestrictedQuerySet.as_manager()
class Meta:
ordering = ['obj_type', 'name', '-created']
def __str__(self):
return str(self.job_id)
def get_absolute_url(self):
# TODO: Fix this to point the right place
return reverse('virtualization:clustertype', args=[self.pk])
@property
def duration(self):
if not self.completed:
@ -546,7 +552,7 @@ class JobResult(models.Model):
args: additional args passed to the callable
kwargs: additional kargs passed to the callable
"""
job_result = cls.objects.create(
job_result: JobResult = cls.objects.create(
name=name,
obj_type=obj_type,
user=user,
@ -556,6 +562,9 @@ class JobResult(models.Model):
queue = django_rq.get_queue("default")
if schedule_at := kwargs.pop("schedule_at", None):
job_result.status = JobResultStatusChoices.STATUS_SCHEDULED
job_result.save()
queue.enqueue_at(schedule_at, func, job_id=str(job_result.job_id), job_result=job_result, **kwargs)
else:
queue.enqueue(func, job_id=str(job_result.job_id), job_result=job_result, **kwargs)