-
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
Allow plugin authors to register housekeeping tasks #16971
Comments
The background jobs framework of #15692 will include the ability to schedule system jobs, i.e. housekeeping or other tasks that run periodically in the background. While the plugin still requires a special management command for interactive execution (optional), periodic execution is covered by this framework. |
I think ultimately we probably want to do away with the separate housekeeping task and integrate everything using the job's framework, particularly in light of @alehaa's recent work. |
The Here are the latest findings:
So the problem for now is to find a way to automatically trigger the setup method outside of the request-response cycle that is called only once or say every few hours. |
How about adding the auto-registration to the beginning of the I'd implement this using a new method in |
This feels like a decent approach. |
I'm not sure if this is possible. Usually the registry handles static variables like a list of middleware to load. To register a |
@jeremystretch can you assign this to me so I can work on a PR? Maybe we can still make it into 4.1. |
@jeremystretch did you have any chance to review this? This would be the last missing piece to add auto-scheduling background tasks, which didn't make it into the |
@alehaa I am not so sure about the approach, I think something more agnostic that can be called after initialization of all apps are done but not specifically tied jobs or RQ might be a better approach. That said, I don't know if there is a viable solution for this as there is no "apps_ready" signal emitted by django. Your solution might be the most viable right now. |
* Fix check for existing jobs 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. * Allow system jobs to be registered A new registry key allows background system jobs to be registered and automatically scheduled when rqworker starts. * Test scheduling of system jobs * Fix plugins scheduled job documentation The documentation reflected a non-production state of the JobRunner framework left over from development. Now a more practical example demonstrates the usage. * Allow plugins to register system jobs * Rename system job metadata To clarify which meta-attributes belong to system jobs, each of them is now prefixed with 'system_'. * Add predefined job interval choices * Remove 'system_enabled' JobRunner attribute 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. * Fix test * Use a decorator to register system jobs * Specify interval when registering system job * Update documentation --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
NetBox version
v4.0.7
Feature type
New functionality
Proposed functionality
NetBox includes a housekeeping management command that usually runs nightly. This command handles:
It would be great if plugin authors could register additional tasks to run by the housekeeping process without having to write their own management commands and setup mechanisms to run those periodically.
Use case
I often have to write periodic tasks to alter model instances in my plugins, reacting to dates, sending emails etc. and having to setup the whole management commands and related mechanisms to run those periodically is not really convenient, even more so considering that NetBox already has mechanisms built in to do so.
Database changes
None whatsoever
External dependencies
None
The text was updated successfully, but these errors were encountered: