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

How to run clean up preserved jobs in cron? #541

Closed
hiendinhngoc opened this issue Mar 14, 2022 · 2 comments
Closed

How to run clean up preserved jobs in cron? #541

hiendinhngoc opened this issue Mar 14, 2022 · 2 comments

Comments

@hiendinhngoc
Copy link

In Clockwork I can do it like this:

  every(1.day, "Cleanup GoodJob preserved jobs", at: "00:00") do
    GoodJob::Job.finished(1.day.ago).delete_all
  end

How can I do the same in good_job cron? I tried with this:

  config.good_job.cron = {
    clean_good_job_preserved_jobs_task: {
      cron: "0 0 * * * bundle exec good_job cleanup_preserved_jobs --before-seconds-ago=86400",
      desciption: "Cleanup GoodJob preserved jobs",
    }
}

but it not working. Error: /user/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/good_job-2.0.5/lib/good_job/cron_manager.rb:87:in create_task': undefined method next_time' for nil:NilClass (NoMethodError)

@bensheldon
Copy link
Owner

There is an alternative mechanism I recommend you use, that will become the default in the next major release of GoodJob (#507):

config.good_job.cleanup_interval_jobs = 1000
config.good_job.cleanup_interval_seconds = 3600

That will delete expired job records after 1k jobs are executed and/or every hour.

To your question directly, GoodJob's cron feature only runs ActiveJob jobs and the cron: key only accepts a schedule (it looks like you tried to use entire line from a crontab that has a shell script; that won't work). If you wanted to use cron, you'd need to wrap up GoodJob.cleanup_preserved_jobs in a job, and then configure that.

@hiendinhngoc
Copy link
Author

Thank you so much for your quick response. I will try your second recommendation.

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

No branches or pull requests

2 participants