Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some basic questions about 'delayed_job'

I'm trying delayed_job now, and have some questions.

From the http://github.com/collectiveidea/delayed_job page, I can see some information:

Workers can be running on any computer, as long as they have access to the database and their clock is in sync. Keep in mind that each worker will check the database at least every 5 seconds.

  1. When I invoke rake jobs:work once, it will create ONE worker, right?

  2. When a worker checks the database, it will read ALL new and failed tasks EACH TIME, and run them?

  3. it says a worker will check the database every 5 seconds, can I make it 2 seconds?

  4. When I create a worker(rake jobs:work), there are already 10 tasks in the database, and each will take 3s. How many processes will DelayedJob create? And how many seconds need in total?

like image 345
Freewind Avatar asked Jul 11 '10 07:07

Freewind


People also ask

How Delayed jobs works?

Delayed::Job works by serializing a Ruby object as YAML and storing it in a database table so that a worker in a different process can retrieve, deserialize, and perform the requested work. Some operations that we use Delayed::Job for are longer-running data processing, sending emails, and updating search indicies.

What is Delayed Job in Rails?

Delayed Job, also known as DJ, makes it easy to add background tasks to your Rails applications on Heroku. You can also use Resque and many other popular background queueing libraries. Delayed Job uses your database as a queue to process background jobs.

How do I know if my job is running late?

The most simple way to check whether delayed_job is running or not, is to check at locked_by field. This field will contain the worker or process locking/processing the job. Running Delayed::Job. where('locked_by is not null') will give you some results, if there are jobs running.


1 Answers

  1. yes
  2. yes
  3. Delayed::Worker.sleep_delay = 2
  4. 1 worker will work on each task in turn, passing or failing it before going onto the next. 30 seconds total + however long 9 sleep delays are for the total time (45 sec. by default). I'm not sure how to answer your question on processes. 1 worker is created, which is a process. Zero or more other processes may be created, depending on what the job to run is.
like image 109
x1a4 Avatar answered Sep 21 '22 16:09

x1a4