Brandon Keepers
2007-Apr-26 19:46 UTC
[Backgroundrb-devel] looking for a worker that''s gone
In my app, I store the job key when a worker is fired off and then check back in periodically to see how its doing. The workers delete themselves when they''re done. I would expect when I try to get a worker that has been deleted, I would get nil or a proper exception, but instead I get: >> MiddleMan.worker(''foobar'') NoMethodError: undefined method `object'' for nil:NilClass from (drbunix:///tmp/backgroundrbunix_localhost_2000) /Users/ brandon/projects/backgroundrb/vendor/plugins/backgroundrb/server/lib/ backgroundrb/middleman.rb:396:in `worker'' I''ve modified MiddleMan#worker to return nil if the job doesn''t exist: def worker(key) worker = ex { @jobs[key].object if @jobs[key] } WorkerProxy.new(worker) unless worker.nil? end What do you think? Brandon -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 186 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20070426/862fca55/attachment.bin
Geoff Garside
2007-Apr-26 21:00 UTC
[Backgroundrb-devel] looking for a worker that''s gone
On 26 Apr 2007, at 20:46, Brandon Keepers wrote:> In my app, I store the job key when a worker is fired off and then > check back in periodically to see how its doing. The workers > delete themselves when they''re done. I would expect when I try to > get a worker that has been deleted, I would get nil or a proper > exception, but instead I get: > > >> MiddleMan.worker(''foobar'') > NoMethodError: undefined method `object'' for nil:NilClass > from (drbunix:///tmp/backgroundrbunix_localhost_2000) / > Users/brandon/projects/backgroundrb/vendor/plugins/backgroundrb/ > server/lib/backgroundrb/middleman.rb:396:in `worker'' > > I''ve modified MiddleMan#worker to return nil if the job doesn''t exist: > > def worker(key) > worker = ex { @jobs[key].object if @jobs[key] } > WorkerProxy.new(worker) unless worker.nil? > end > > What do you think? > > Brandon > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-develCertainly seems like a good idea to me. It is a little messy to be testing for a NoMethodError when checking to see if a worker is still alive. At the same time though you can currently do MiddleMan.jobs.has_key?(:my_worker_key) Geoff
(resending to include list, sorry for the double email Geoff) This was the workaround I ended up using in my app. Maybe this check should be done in #worker before it tries to evaluate #object on nil? Looks like there''s a ticket covering this: http://backgroundrb.devjavu.com/projects/backgroundrb/ticket/47 On 4/27/07, Geoff Garside <ruby at geoffgarside.co.uk> wrote:> On 26 Apr 2007, at 20:46, Brandon Keepers wrote: > > > In my app, I store the job key when a worker is fired off and then > > check back in periodically to see how its doing. The workers > > delete themselves when they''re done. I would expect when I try to > > get a worker that has been deleted, I would get nil or a proper > > exception, but instead I get: > > > > >> MiddleMan.worker(''foobar'') > > NoMethodError: undefined method `object'' for nil:NilClass > > from (drbunix:///tmp/backgroundrbunix_localhost_2000) / > > Users/brandon/projects/backgroundrb/vendor/plugins/backgroundrb/ > > server/lib/backgroundrb/middleman.rb:396:in `worker'' > > > > I''ve modified MiddleMan#worker to return nil if the job doesn''t exist: > > > > def worker(key) > > worker = ex { @jobs[key].object if @jobs[key] } > > WorkerProxy.new(worker) unless worker.nil? > > end > > > > What do you think? > > > > Brandon > > _______________________________________________ > > Backgroundrb-devel mailing list > > Backgroundrb-devel at rubyforge.org > > http://rubyforge.org/mailman/listinfo/backgroundrb-devel > > Certainly seems like a good idea to me. > > It is a little messy to be testing for a NoMethodError when checking > to see if a worker is still alive. At the same time though you can > currently do > > MiddleMan.jobs.has_key?(:my_worker_key) > > Geoff > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >