Duplicate schedule using delayed_job

Is it possible to do the following with delayed_job:

  • Define a class named Tasks

  • You have a method in Tasks that runs every 5 minutes: Tasks.do_processing

  • When the next five minute loop appears, run Tasks.do_processing only if the previous do_processing completed

Is this something I need to create on my own or it may linger (or some other gem / plugin) to do this?

Ps. I know about cron jobs for the OS level, but if I used this, it would mean that every time cron "starts", it reloads the entire Rails environment, and delayed_job only needs to be loaded once.

+4
source share
6 answers

You might consider creating a Rake task or other similar autonomous processes that perform this function and then complete it with Daemons

What are demons?

Daemons provides an easy way to wrap existing ruby ​​scripts (like a standalone server) to run as a daemon and be controlled by a simple start / stop / restart.

If you want, you can also use daemons to run ruby ​​code blocks in a process daemon and manage these processes from the main application.

In addition to this basic functionality, daemons offer many additional functions like reverse tracking of exceptions and registration (in case of ruby ​​script failure) and monitoring and automatic restart of your processes if they fail.

+5
source

If you want to do something like this:

 class MyJob run_every 1.day def perform # code to run ... end end 

then try this code: https://gist.github.com/1024726

+5
source

DJ 2.1 has been using the this version for some time. No hackers, uses Delayed Jobs built into hooks. Just make sure you add a column called "queue" to the slow-motion table, which I think adds DJ 3 to the table.

+1
source
0
source

I think I could add that the delayed_job_recurring gem is an entity extension in @kares answer.

Usage example:

 class MyTask include Delayed::RecurringJob run_every 1.day run_at '11:00am' timezone 'US/Pacific' queue 'slow-jobs' def perform # Do some work here! end end 

And plan it. In the rails application, you can put this in the initializer:

 MyTask.schedule! 
0
source

You can use https://github.com/codez/delayed_cron_job , which is a task delay plugin for setting periodic tasks.

0
source

Source: https://habr.com/ru/post/1344405/


All Articles