Skip to content

Job scheduling is not working #18004

@miaow2

Description

@miaow2

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    netboxstatus: duplicateThis issue has already been raisedtype: bugA confirmed report of unexpected behavior in the application

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions