views:

85

answers:

1

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?

+4  A: 
  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.
x1a4
@x1a4, thank you. And could you see my updated question, there is one more question :)
Freewind
Is there anyway to speed up? I mean, can these tasks be executed in parallel?
Freewind
run multiple workers
x1a4
Sorry, the question 4 has been updated. For now, the total time should be 30s, right?
Freewind
30 seconds, plus the sleep time between each job (which by default is an additional 45 seconds total)
x1a4
30 + 5*9? Do you mean although the worker has got 10 tasks, but it will sleep for 5 seconds(default) after executing each task?
Freewind
If there are 10 tasks in the database, how many tasks a work will get each time? ONE? or TEN?
Freewind
"Do you mean although the worker has got 10 tasks, but it will sleep for 5 seconds(default) after executing each task?" - Yes, exactly
x1a4
"If there are 10 tasks in the database, how many tasks a work will get each time? ONE? or TEN?"Ok, 10 tasks, and you start 1 worker. That worker grabs the first unfinished task in the queue that's set to run, and tries to do it. If it's successful, it's recorded, and by default removed from the queue. If it fails, that is recorded, and a timestamp is set for the next time it would run. (continued in next comment, heh.)
x1a4
This first job is considered 'done', for now, and the same worker now sleeps for that default 5 seconds, then grabs the next job in the queue, and runs it. So the same worker will eventually attempt all 10 tasks. If all of them pass, none of them will be run again. Any failed task will be tried up to 20 times, by default, before it's failed permanently. All of this would be done by the single worker. If you use multiple workers, dj will keep track and make sure multiple workers don't try to run the same job (by locking the job, so a worker would just go to the next one if it sees it.)
x1a4