Skip to content

Conversation

@kkthxbye-code
Copy link
Contributor

@kkthxbye-code kkthxbye-code commented Sep 20, 2022

Fixes: #8366

This is a draft PR for adding job scheduling. Feel free to provide input.

Changes:

  • Add a "Schedule at" form field to both the report and script form
  • Add JobResult list view
  • Add the form-object-edit class to both forms to match the width of forms in the rest of netbox (previously they were full width)
  • Update the js flatpickr dependency to fix issue with the DateTimeField automatically populating when losing focus.
  • Modify JobResult to delete RQ tasks to avoid running scheduled tasks with no JobResult associated
  • Added new JobResultStatusChoice Scheduled
  • Added new field scheduled_time to JobResult model
  • Show scheduled time when viewing a job result
  • Add --with-scheduler option to rqworker management command
  • Added small snippet to docs about scheduling jobs
  • REST API changes:
    • Added scheduled_time to JobResult

To do:

  • Add job scheduling support to the API as well?
  • limit_choices_to=FeatureQuery('job_results'), doesn't work at all in filter forms and it doesn't seem to work in other filterforms either.

@kkthxbye-code kkthxbye-code self-assigned this Sep 20, 2022
@jeremystretch
Copy link
Member

@kkthxbye-code thanks for taking this on. I wanted to note that since this has been tagged for v3.4, the PR should be based on the feature branch.

@jeremystretch jeremystretch added the beta Concerns a bug/feature in a beta release label Sep 26, 2022
@kkthxbye-code kkthxbye-code changed the base branch from develop to feature September 26, 2022 14:39
@kkthxbye-code
Copy link
Contributor Author

@jeremystretch - Thanks, didn't notice when I opened the PR that it was the wrong target branch, the actual branch was made off of feature though, so it shouldn't be an issue. I changed the target now :)

* Added JobResult form filtersets
* Change housekeeping cleanup delete from `_raw_delete` to `delete` to make sure scheduled tasks are cancelled
* Change default sort of JobResult table to -created
* Added `delete` override to `JobResult` to remove scheduled tasks from RQ when a JobResult is deleted
* Updated js/css dist files. Will need to be redone when develop is merged to feature.
Done to avoid having deleted a task on accident if the deleting of the JobResult fails.
@kkthxbye-code kkthxbye-code marked this pull request as ready for review October 16, 2022 16:17
@kkthxbye-code
Copy link
Contributor Author

kkthxbye-code commented Oct 16, 2022

I think this is ready for initial review now @jeremystretch

There's some stuff I'm unsure about:

  • I moved job results out of the admin panel. Do we want another list view called scheduled jobs? It would be the same exact table as the job results table, just filtered to only contain job results with the scheduled status.
  • Should I add support for scheduling jobs to the API as well? Fixed
  • Currently the way to cancel a job is to delete the associated job result. Do we want to add another method that just cancels the schedule but lets the job result instance be?

I probably forgot some stuff, but let me know if something is not clear when testing.

@jeremystretch
Copy link
Member

Do we want another list view called scheduled jobs?

Can we just add a filter for the primary list?

Currently the way to cancel a job is to delete the associated job result. Do we want to add another method that just cancels the schedule but lets the job result instance be?

Possibly; I'm happy to defer to feedback we receive during the beta cycle.

Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work @kkthxbye-code! A couple minor comments but overall this is excellent! Thanks for owning this.

@kkthxbye-code
Copy link
Contributor Author

Can we just add a filter for the primary list?

It is already possible to filter by status in the JobResult view. We could add a menu item that links to the JobResult list with the status pre-filtered to Schedules but not sure if it is necessary.

Thank you for the review, I adressed what I could. Regarding the filtersets I'm gonna need some guidance.

@jeremystretch
Copy link
Member

Awesome work @kkthxbye-code! 🙌

@jeremystretch jeremystretch merged commit 5d56d95 into netbox-community:feature Oct 21, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

beta Concerns a bug/feature in a beta release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to schedule scripts & reports

2 participants