Dylan Markow
2008-Apr-04 03:57 UTC
[Backgroundrb-devel] First call to worker method doesn''t work
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.
Dylan Markow
2008-Apr-04 05:12 UTC
[Backgroundrb-devel] First call to worker method doesn''t work
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).
Dylan Markow
2008-Apr-04 05:24 UTC
[Backgroundrb-devel] First call to worker method doesn''t work
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.
hemant
2008-Apr-04 08:25 UTC
[Backgroundrb-devel] First call to worker method doesn''t work
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.
hemant kumar
2008-Apr-10 22:17 UTC
[Backgroundrb-devel] First call to worker method doesn''t work
On Thu, 2008-04-03 at 22:24 -0700, Dylan Markow 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.Hi Dylan, Sorry for late reply, but I think I nailed down issues you mentioned. But you need to get latest code, which is not yet in git repo: 1. First update your packet. Get packet code from here: http://code.google.com/p/packet/source/checkout Install using: rake gem; sudo gem install packet-0.1.6.gem 2. Get backgroundrb code with fixes from: http://backgroundrb.gnufied.org/manual/backgroundrb.tar.gz Now, you are set. Your problems were because of a bug in Ruby itself and hence I have reverted connection to old style of connecting on each request. There was a bug in packet itself for frequent connection/disconnection. See, if above fixes your problem. I will be publishing both softwares upstream in few days.
Brian
2008-Apr-28 21:35 UTC
[Backgroundrb-devel] First call to worker method doesn''t work
I''m facing this same issue. Tried to follow hemant''s recommendation http://rubyforge.org/pipermail/backgroundrb-devel/2008-April/001675.html But get an error when running the Rake task: rake aborted! no such file to load -- spec/rake/spectask /Users/brian/packet-read-only/rakefile:7 (See full trace by running task with --trace) I''m not a rake or a gem guy, so have no clue what to do. The file / spec/rake/spectask doesn''t exist. Thanks.