-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closes #16971: Add system jobs #17716
base: feature
Are you sure you want to change the base?
Conversation
@alehaa I think we might have jumped the gun a bit on FR #16971: Because this is introducing a new plugin capability, it needs to be tagged for a minor release. (We can't ship any changes to the plugins API in a patch release.) I have no issue tagging for v4.2 though. Are okay with rebasing this against the |
That's fine by me. Do you initiate the rebase or do I have to do it locally and submit a new PR? |
I should be able to tackle the rebase, just wanted to give you a heads up. |
bf88f18
to
5b61d14
Compare
5b61d14
to
191552f
Compare
191552f
to
3091fa5
Compare
If a job is to be enqueued once and no specific scheduled time is specified, any scheduled time of existing jobs will be valid. Only if a specific scheduled time is specified for 'enqueue_once()' can it be evaluated.
A new registry key allows background system jobs to be registered and automatically scheduled when rqworker starts.
The documentation reflected a non-production state of the JobRunner framework left over from development. Now a more practical example demonstrates the usage.
To clarify which meta-attributes belong to system jobs, each of them is now prefixed with 'system_'.
3091fa5
to
8a8c328
Compare
Previously, the 'system_enabled' attribute was used to control whether a job should run or not. However, this can also be accomplished by evaluating the job's interval.
logger.debug(f"Scheduling system job {job.name} (interval={interval})") | ||
job.enqueue_once(**kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From 6b192c9 there is a missing if interval:
.
The reason for this if-statement is to selectively ignore job registration, e.g. depending on configuration parameters. An example use case would be not to register the changelog cleanup job if the CHANGELOG_RETENTION
setting is zero (disabled). If there are other ways to accomplish this (maybe by another decorator before system_jon()
?) I'm open to that solution as well.
) | ||
|
||
|
||
def system_job(interval): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest adding *args, **kwargs
as arguments, storing them in the registry and passing them to enqueue_once()
. This would allow plugins to reuse jobs for different actions. Practical example: Changelog and journal cleanup could use the same job and pass model/configuration parameter names as arguments.
Fixes: #16971
This PR allows the NetBox core and plugins to register job runners as system jobs. These are automatically scheduled without UI interaction, just before the worker process starts. This allows job runners to be used for housekeeping and synchronization tasks in future commits.