Skip to content
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

Open
wants to merge 13 commits into
base: feature
Choose a base branch
from

Conversation

alehaa
Copy link
Contributor

@alehaa alehaa commented Oct 9, 2024

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.

@jeremystretch
Copy link
Member

@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 feature branch? It shouldn't present much conflict.

@alehaa
Copy link
Contributor Author

alehaa commented Oct 11, 2024

That's fine by me. Do you initiate the rebase or do I have to do it locally and submit a new PR?

@jeremystretch
Copy link
Member

I should be able to tackle the rebase, just wanted to give you a heads up.

@jeremystretch jeremystretch force-pushed the 16971-housekeeping branch 2 times, most recently from bf88f18 to 5b61d14 Compare October 11, 2024 15:28
@jeremystretch jeremystretch changed the base branch from develop to feature October 11, 2024 15:29
@jeremystretch jeremystretch added this to the v4.2 milestone Oct 11, 2024
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_'.
netbox/netbox/utils.py Outdated Show resolved Hide resolved
netbox/netbox/utils.py Outdated Show resolved Hide resolved
netbox/core/management/commands/rqworker.py Outdated Show resolved Hide resolved
alehaa and others added 6 commits October 27, 2024 11:17
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.
Comment on lines +25 to +26
logger.debug(f"Scheduling system job {job.name} (interval={interval})")
job.enqueue_once(**kwargs)
Copy link
Contributor Author

@alehaa alehaa Oct 30, 2024

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):
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow plugin authors to register housekeeping tasks
4 participants