background-jobs.md 2.3 KB

Background Jobs

NetBox includes the ability to execute certain functions as background tasks. These include:

Additionally, NetBox plugins can enqueue their own background tasks. This is accomplished using the Job model. Background tasks are executed by the rqworker process(es).

Job Access

Each job has an access class, which determines who may access it in addition to the permissions assigned for jobs:

  • Requester - Only the user who created the job. Jobs for background REST API bulk operations and background UI operations use this class.
  • Object - Only users permitted to view the job's assigned object. For example, the results of a custom script are visible only to users permitted to view the script, and those of a data source synchronization only to users permitted to view the data source.
  • Shared - Any user permitted to view jobs. Housekeeping and other system jobs use this class.

Superusers can access all jobs regardless of access class. The access class applies to every action, so only superusers can view or delete another user's requester jobs, even if permitted to delete jobs. (Housekeeping still purges all jobs under JOB_RETENTION.)

Job Lifetime

!!! info "This feature was introduced in NetBox v4.8."

A job runner may declare a lifetime for the jobs it creates. Once such a job has finished (whether completed, failed, or errored), it expires when its lifetime runs out, and is deleted by a system job which runs hourly. Pending, scheduled, and running jobs never expire. For example, the jobs for background REST API bulk operations have a lifetime of 24 hours.

A job's lifetime applies regardless of the JOB_RETENTION setting, which remains an upper limit: a job is deleted when it expires or when it exceeds the retention period, whichever comes first. Jobs without a lifetime are subject only to JOB_RETENTION.

Scheduled Jobs

Background jobs can be configured to run immediately, or at a set time in the future. Scheduled jobs can also be configured to repeat at a set interval.