[Backgroundrb-devel] First call to worker method doesn't work

hemant gethemant at gmail.com
Fri Apr 4 04:25:55 EDT 2008


On 4/4/08, Dylan Markow <dmarkow at gmail.com> wrote:
> On Thu, Apr 3, 2008 at 10:12 PM, Dylan Markow <dmarkow at gmail.com> wrote:
>  >
>  > On Thu, Apr 3, 2008 at 8:57 PM, Dylan Markow <dmarkow at gmail.com> wrote:
>  >  > I have a worker as follows:
>  >  >
>  >  >  class SampleWorker < BackgrounDRb::MetaWorker
>  >  >   set_worker_name :sample_worker
>  >  >   def create(args = nil)
>  >  >     # this method is called, when worker is loaded for the first time
>  >  >   end
>  >  >
>  >  >   def my_method
>  >  >     # Deliver test e-mail message
>  >  >     Notifications.deliver_message(1, "DM")
>  >  >   end
>  >  >  end
>  >  >
>  >  >  I have a rails controller that calls the following code:
>  >  >
>  >  >     worker = MiddleMan.worker(:sample_worker)
>  >  >     worker.my_method
>  >  >
>  >  >  The problem is that the first time I load up the page for this action,
>  >  >  the worker method "my_method" doesn't seem to ever get called. There
>  >  >  is zero output from any of the backgroundrb log files. If I then
>  >  >  reload the page, it works fine (and continues to work fine until
>  >  >  backgroundrb is restarted).
>  >  >
>  >  >  This happens whether I'm in dev. or prod. mode.
>  >  >
>  >
>  >  To clarify, if I restart rails AND backgroundrb at the same time,
>  >  everything works fine. it's only if backgroundrb needs to restart on
>  >  its own for some reason. It looks like when the backgroundrb process
>  >  is restarted, rails doesn't realize this as it still sees port 11006
>  >  open. So my first request to the page results in the rails plugin
>  >  attempting to write data to the socket. I'm assuming this screws
>  >  something up, as upon the second attempt at loading my page, "rescue
>  >  Errno::EPIPE" at line 64 of backgroundrb.rb is called, thus
>  >  re-establishing the connection. I'm assuming this problem may be more
>  >  closely related to the packet gem? (Not sure if there is a trac repo
>  >  for packet).
>  >
>
>
>
> One last note: If you have 5 mongrels running of your rails app, then
>  the worker will fail to fire 5 times (once for each mongrel), though
>  not always in a row (typically my second request works, but then my
>  3rd or 4th, etc., won't)
>
>  As it stands now, I'm setting up my deployment files to always restart
>  backgroundrb BEFORE rails to make sure that once each mongrel fires
>  up, they each have a valid instance of backgroundrb to point to.
>

I am tracking down this problem and its related to a bug in ruby
itself (See my post on ruby-core mailing list). In the meanwhile, we
can switch back to starting new connection on each request as a
workaround.


More information about the Backgroundrb-devel mailing list