Brett Walker
2006-Aug-25 05:18 UTC
[Backgroundrb-devel] repeat_every when a worker is not done yet...
If I use repeat_every for a worker, if the do_work function has not completed by the time the next interval rolls around, will a new thread be started, resulting in 2 threads for the same worker? Looking at start_process, it seems like the thread gets created (which spins off the thread and then continues to execute the start_process method, right?), then sets the @next_start. So if the @next_start is in 10 minutes, but it takes 20 minutes to finish the current work, start_timer will attempt to call start_process on the job, and kick off another thread, resulting in 2 threads. Is this correct? What I want to happen is that the thread can''t get kicked off again until the current one has completed/returned. Maybe the setting of @next_start needs to go in the thread block. Or did I totally misunderstand the code? Cheers, Brett
Ezra Zygmuntowicz
2006-Aug-25 15:14 UTC
[Backgroundrb-devel] repeat_every when a worker is not done yet...
On Aug 24, 2006, at 10:18 PM, Brett Walker wrote:> If I use repeat_every for a worker, if the do_work function has not > completed by the time the next interval rolls around, will a new > thread be started, resulting in 2 threads for the same worker? > > Looking at start_process, it seems like the thread gets created (which > spins off the thread and then continues to execute the start_process > method, right?), then sets the @next_start. So if the @next_start is > in 10 minutes, but it takes 20 minutes to finish the current work, > start_timer will attempt to call start_process on the job, and kick > off another thread, resulting in 2 threads. > > Is this correct? What I want to happen is that the thread can''t get > kicked off again until the current one has completed/returned. Maybe > the setting of @next_start needs to go in the thread block. Or did I > totally misunderstand the code? > > Cheers, > BrettHey Brett- You know I think you are correct. It looks like if your worker lasts longer then the interval that you will end up with multiple worker threads. Hmm.. I personally haven''t used the repeat_every stuff. I added unit tests for it when the patch was submitted but I don''t think I considered the case you are talking about. I am in the middle of a wholesale refactoring of the codebase in order to add a thread pool and more precise timed workers. Hopefully sometime next week I will have a release. If you need this right away then I would happily accept a patch for more detailed cron style workers. Cheers- -Ezra