How does the Delayed Job work in Ruby on Rails?

Am I new to this and a little confused about how the Delayed Job works?

I know that it creates a table and places the tasks in the table, and then I need to run

rake jobs:work

to start the background process. Now my question

  • Does the DJ script check every table every minute, and when the time corresponds to the task_ task, does this task run?

  • How is it different from cron (whenever gem) if the script just checks the table every min?

thank

+5
source share
2 answers
  • Does the DJ script check every table every minute, and when the time is the same as the job_at time, is this work done?

rake jobs:work DelayedJob delayed_jobs, , job_at, . , .

  1. cron ( , gem), script min?

whenever - , crontab. .

cron , , delayed_job .

  • cron , delayed_job , 1- cron
  • , cron , Rails, . , , .

delayed_job cron , - crontab

* * * * * RAILS_ENV=production script/delayed_job start --exit-on-complete

delayed_job , , , . , . delayed_job - .

+6

DJ script ​​ job_at time, ?

. 5 .

cron ( , gem), script ?

. , .

          DJ                  |            Crontab
 uses additional database     | you should either set up a rake task
 table but that it. easier  | or a runner which can be called on the
 to code compared to crontab  | crontab
------------------------------|------------------------------------------
 requires you to run a worker | requires you to setup your cron which
 that will poll the database  | you can easily do using the whenever gem
------------------------------|------------------------------------------
 since this uses a table, it  | you have to setup some sort of logging so
 is easier to debug errors    | that you have an idea what caused the error
 when they happen             |
------------------------------|------------------------------------------
 the worker should always be  | as long as your crontab is set up properly,
 running to perform the job   | you should have no issues
------------------------------|------------------------------------------
 harder to setup recurring    | easy to setup recurring tasks
 tasks                        |
------------------------------|------------------------------------------
+4

All Articles