⚙️ Add auto-cleanup for GoodJob (when applicable) #2043
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit introduces automatic clean-up of finished successful Good
Job jobs. It is here to help with the overall performance of GoodJobs
as well as the application database. Note the cleanup schedule is a
guess on what's appropriate.
Code Walk Through of Good Jobs Configuration
The
README
explains the configuration for the Scheduler.
Here's the implementation of
GoodJob::Configuration
regarding the cleanup_interval_seconds. Which is in the
GoodJob::CleanupTracker
.The
GoodJob::CleanupTracker
has a
#cleanup?
method that looks at either job counts or elapsedseconds. Which informs the
GoodJob::Scheduler
.The
GoodJob::Scheduler
observes the tasks as they complete. And one of those is conditionally
running
#cleanup
.The
GoodJob::Scheduler's
#cleanup
method delegates the clean_up to the performer; which is aGoodJob::JobPerformer
.The
GoodJob::JobPerformer
then runs the general process
GoodJob.cleanup_preserved_jobs
(which isavailable via the CLI).
The
GoodJob.cleanup_preserved_jobs
method is the one that ultimately cleans up preserved jobs.
Note that the
include_discarded
does some logical hoops with somegrammatical antics (e.g.
old_jobs.not_discarded unless include_discarded
). We are not including discarded jobs so the querywill limit to jobs that are not_discarded.
Related to:
@samvera/hyku-code-reviewers