How to create a daily job (cron-like) in Rails ActiveJob?

rilut picture rilut · Mar 31, 2015 · Viewed 9.4k times · Source

I'm aware of this thread: A cron job for rails: best practices?, but there's no mention of ActiveJob. My motivation to do it with ActiveJob is because it's built-in in Rails and here's an excerpt from its docs:

"These jobs can be everything from regularly scheduled clean-ups, to billing charges, to mailings."

How do I create a daily job (cron-like) in Rails ActiveJob? Since I don't see the example to run a regularly scheduled job in its docs.

Or should I stick with the whenever gem?

Answer

joelparkerhenderson picture joelparkerhenderson · Mar 31, 2015

Stick with the whenever gem or similar gem e.g. chrono, clockwork, rufus-scheduler.

What you're reading in the ActiveJob documentation is a bit confusing, because it could seem as if ActiveJob may be able handle the responsibility of regular scheduling. What the documentation should say IMHO is that the jobs are regularly scheduled by some other system or tool.

So, ActiveJob is about queued jobs?

Yes, it's about Rails providing a standard interface for adding a job to a queue, and calling a perform method. ActiveJob provides the method interfaces that enable adapters for many job-processing queues, backends, immediate runners, etc.