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

Have demo CleanupJob use GoodJob.cleanup_preserved_jobs #470

Merged
merged 1 commit into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/good_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def self._shutdown_all(executables, method_name = :shutdown, timeout: -1)
# analyze or inspect job performance.
# If you are preserving job records this way, use this method regularly to
# delete old records and preserve space in your database.
# @params older_than [nil,Numeric,ActiveSupport::Duration] Jobs olders than this will be deleted (default: +86400+).
# @params older_than [nil,Numeric,ActiveSupport::Duration] Jobs older than this will be deleted (default: +86400+).
# @return [Integer] Number of jobs that were deleted.
def self.cleanup_preserved_jobs(older_than: nil)
older_than ||= GoodJob::Configuration.new({}).cleanup_preserved_jobs_before_seconds_ago
Expand Down
7 changes: 2 additions & 5 deletions spec/test_app/app/jobs/cleanup_job.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
class CleanupJob < ApplicationJob
self.queue_name = :cleanup

def perform(limit = 1_000)
earliest_job_to_preserve = GoodJob::Execution.finished.order(created_at: :desc).limit(limit).last
return if earliest_job_to_preserve.blank?

GoodJob::Execution.where("created_at < ?", earliest_job_to_preserve.created_at).delete_all
def perform(*args)
GoodJob.cleanup_preserved_jobs
end
end