netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
16.37k stars 2.6k forks source link

Job scheduling is not working #18004

Closed miaow2 closed 1 week ago

miaow2 commented 2 weeks ago

Deployment Type

Self-hosted

Triage priority

I volunteer to perform this work (if approved)

NetBox Version

v4.1.6

Python Version

3.11

Steps to Reproduce

  1. Create any script
from extras.scripts import Script

class TestScript(Script):

    def run(self, data, commit):
        self.log_info("This is test script")
  1. Run the script with any interval set image

Expected Behavior

The script successfully runs and creates a new scheduled job

Observed Behavior

A new job is not scheduled, traceback from worker

13:48:59 default: handle(commit=True, data={}, job=<Job: 086a5aae-5c60-4746-bde4-f77800c795ea>, request=<utilities.request.NetBoxFakeRequest object at 0x7fba0c3b7ef0>) (086a5aae-5c60-4746-bde4-f77800c795ea)
13:48:59 [Job 086a5aae-5c60-4746-bde4-f77800c795ea]: exception raised while executing (handle)
Traceback (most recent call last):
  File "/home/miaow/work/netbox/venv/lib/python3.12/site-packages/rq/worker.py", line 1430, in perform_job
    rv = job.perform()
         ^^^^^^^^^^^^^
  File "/home/miaow/work/netbox/venv/lib/python3.12/site-packages/rq/job.py", line 1280, in perform
    self._result = self._execute()
                   ^^^^^^^^^^^^^^^
  File "/home/miaow/work/netbox/venv/lib/python3.12/site-packages/rq/job.py", line 1317, in _execute
    result = self.func(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/miaow/work/netbox/netbox/netbox/jobs.py", line 74, in handle
    cls.enqueue(
  File "/home/miaow/work/netbox/netbox/netbox/jobs.py", line 107, in enqueue
    return Job.enqueue(cls.handle, name=name, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/miaow/work/netbox/netbox/core/models/jobs.py", line 237, in enqueue
    job.full_clean()
  File "/home/miaow/work/netbox/venv/lib/python3.12/site-packages/django/db/models/base.py", line 1502, in full_clean
    raise ValidationError(errors)
django.core.exceptions.ValidationError: {'name': ['This field cannot be blank.']}

This happens because the rescheduling mechanism does not pass name to the Job enqueue and name field is obligatory in Job model.

This can be fixed by passing job.name to cls.enqueue here.

Feel free to assign this issue to me, I will create PR to fix this issue.A new

alehaa commented 2 weeks ago

This issue is a duplicate of https://github.com/netbox-community/netbox/issues/17923, https://github.com/netbox-community/netbox/issues/17921. A PR is already provided and ready to merge. :)

jeremystretch commented 1 week ago

This appears to be a duplicate of #17921, which has been resolved by PR #17932.