[Backgroundrb-devel] worker starting twice
masonhale at gmail.com
Wed Mar 14 11:49:08 EDT 2007
My understanding is that for scheduled workers, the do_work method is called
automatically when the worker is created (which provides an opportunity for
any initialization, if necessary), and subsequently the :worker_method
specified in the backgroundrb_schedules.yml file is called on the specified
If your worker_method is specified as :do_work, then your :do_work method
will be called twice, once when the worker is created, and again when the
schedule is invoked. Note that these separate calls can occur in separate
threads. So if you do use the call to do_work at creation time to do some
initialization, you will need to set a flag internally to let other
(potentially simultaneous) calls to your :worker_method behave appropriately
if called be initialization is complete.
Here's the relevant excerpt from the documentation:
> Special case: :do_work
> The do_work method of a worker is automatically called when you first
> create a worker and we are treating it differently than other methods when
> you schedule.
> You can have do_work executed repeatedly in a schedule by specifying
> :worker_method => :do_work in schedule_worker. What will happen, is that on
> the initial schedule where a worker is created, it will call the built in
> call to do_work, then on subsequent trigger events, use the :worker_method.
I believe the documentation should be corrected -- the "on subsequent
trigger events" part is not exactly accurate, as the trigger event could be
simultaneous, and hence not "subsequent".
On 3/14/07, Jack Nutting <jnutting at gmail.com> wrote:
> On 3/13/07, Brian Lucas <blucasco at gmail.com> wrote:
> > Hi Jack, I'm experiencing the same problem and wrote about it here
> > I wonder if it has something to do with thread_pool size or concurrent
> > threads running in brb?
> I don't know, but I know it's really irritating.
> I think I have a few clues for whoever feels up to looking at this.
> First of all, the doubled worker is not actually running in two
> processes. 'ps' shows me only the processes i've specified in the
> schedules file, not more. Instead, the trigger method is being called
> twice. Through logging output, I've observed that my loop is in fact
> running twice simultaneously, presumably from two different threads.
> Also, I've found a way to determine which of my processes will be
> doubled: whichever top-level job entry name (not the job_key, but the
> top-level identifier for a worker) comes alphabetically first, that's
> the job that I start getting double-invocations on! e.g. if I have a
> job like this:
> :class: :my_class
> :job_key: :my_job1
> that won't won't be doubled up (some other worker will instead).
> However, if I change the 'zzzzz' to 'a', this worker will be
> double-invoked. In the short term, this gives me a workaround since I
> can have a dummy worker called 'a' that just sleeps, but this is still
> consuming excess RAM of course.
> // jack
> // http://www.nuthole.com
> Backgroundrb-devel mailing list
> Backgroundrb-devel at rubyforge.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Backgroundrb-devel