Tomasz Kaye
2007-Jan-15 15:32 UTC
[Backgroundrb-devel] Instantiating middleman and worker from inside a model?
In short: how (if possible) would i go about arranging it so that i can instantiate a middleman and set a worker going from within a method in one of my models? or is this a weird thing to be wanting to do? ( My specific situation: I have an ''Image'' model in my application. An actual image file associated with the model is being stored on amazons s3 system. I''d like to use a worker to handle each s3 operation (eg. deleting the image from s3). The Image model seems the neatest place to set the worker going but I''m a little stumped as to how i should modify my model to enable the instantiation of middleman within it. thanks in advance for any pointers! (apologies in advance if this message gets posted twice; i think my previous attempt didn''t work)
Joshua Bates
2007-Jan-15 18:51 UTC
[Backgroundrb-devel] Instantiating middleman and worker from inside a model?
Just call work_thread on the worker. Something like.... def save_to_s3 worker.work_thread(:method => :save, :args => [args]) end def worker @worker ||= MiddleMan.worker(:s3) end If you need to pass the whole model to the worker, make sure to add include DRbUndumped in your model. On 1/15/07, Tomasz Kaye <tomasz at resourcestudio.nl> wrote:> > In short: how (if possible) would i go about arranging it so that i > can instantiate a middleman and set a worker going from within a > method in one of my models? or is this a weird thing to be wanting to > do? ( > > My specific situation: I have an ''Image'' model in my application. An > actual image file associated with the model is being stored on > amazons s3 system. I''d like to use a worker to handle each s3 > operation (eg. deleting the image from s3). The Image model seems the > neatest place to set the worker going but I''m a little stumped as to > how i should modify my model to enable the instantiation of middleman > within it. > > thanks in advance for any pointers! > > (apologies in advance if this message gets posted twice; i think my > previous attempt didn''t work) > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20070115/8c04f408/attachment.html
Tomasz Kaye
2007-Jan-16 14:11 UTC
[Backgroundrb-devel] Instantiating middleman and worker from inside a model?
Thanks joshua, i thought i had tried this before but evidently i had something wrong, it''s working fine now :) On Jan 15, 2007, at 7:51 PM, Joshua Bates wrote:> Just call work_thread on the worker. > Something like.... > > def save_to_s3 > worker.work_thread(:method => :save, :args => [args]) > end > > def worker > @worker ||= MiddleMan.worker(:s3) > end > > If you need to pass the whole model to the worker, make sure to add > include DRbUndumped in your model. > > On 1/15/07, Tomasz Kaye < tomasz at resourcestudio.nl> wrote: > In short: how (if possible) would i go about arranging it so that i > can instantiate a middleman and set a worker going from within a > method in one of my models? or is this a weird thing to be wanting to > do? ( > > My specific situation: I have an ''Image'' model in my application. An > actual image file associated with the model is being stored on > amazons s3 system. I''d like to use a worker to handle each s3 > operation (eg. deleting the image from s3). The Image model seems the > neatest place to set the worker going but I''m a little stumped as to > how i should modify my model to enable the instantiation of middleman > within it. > > thanks in advance for any pointers! > > (apologies in advance if this message gets posted twice; i think my > previous attempt didn''t work) > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20070116/c006ebc7/attachment.html
Tomasz Kaye
2007-Jan-16 16:43 UTC
[Backgroundrb-devel] Instantiating middleman and worker from inside a model?
I spoke too soon, i''m still stuck with the same problem (sorry). Perhaps if i show how my model looks it''ll be obvious what i''m doing wrong; class Image < ActiveRecord::Base def destroy s3delete super end def s3delete) MiddleMan.new_worker( :class => :s3_worker ) end end When i call destroy on an image model I''m getting the error: "NameError (uninitialized constant S3Worker):" . which is to be expected i suppose. How should i make S3Worker visible in this scope? thanks again. On Jan 15, 2007, at 7:51 PM, Joshua Bates wrote:> Just call work_thread on the worker. > Something like.... > > def save_to_s3 > worker.work_thread(:method => :save, :args => [args]) > end > > def worker > @worker ||= MiddleMan.worker(:s3) > end > > If you need to pass the whole model to the worker, make sure to add > include DRbUndumped in your model. > > On 1/15/07, Tomasz Kaye < tomasz at resourcestudio.nl> wrote: > In short: how (if possible) would i go about arranging it so that i > can instantiate a middleman and set a worker going from within a > method in one of my models? or is this a weird thing to be wanting to > do? ( > > My specific situation: I have an ''Image'' model in my application. An > actual image file associated with the model is being stored on > amazons s3 system. I''d like to use a worker to handle each s3 > operation (eg. deleting the image from s3). The Image model seems the > neatest place to set the worker going but I''m a little stumped as to > how i should modify my model to enable the instantiation of middleman > within it. > > thanks in advance for any pointers! > > (apologies in advance if this message gets posted twice; i think my > previous attempt didn''t work) > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20070116/67b95e18/attachment.html
Jacob Robbins
2007-Jan-16 16:58 UTC
[Backgroundrb-devel] Instantiating middleman and worker from inside a model?
as i understand it the S3Worker class does not need to be visible in the scope of the Image model. Only the MiddleMan class needs to be visible. You pass the :s3_worker symbol to the MiddleMan class and it uses that symbol to find the correct class on the other side of the drb connection (ie in the backgroundrb_server process, not here in the rails process). So i suggest going through a laundry list of different situations to see if this works anywhere in your code. -is that erroneous parentheses in "def s3delete)" only in your email? -can you call worker(:class => s3_worker) from the backgroundrb console? -try making a different method for the image class does nothing but instantiate an s3_worker and calling it in the rails console. -double check the class code for S3Worker to make sure the symbol :s3_worker will clearly resolve to both the class name and the file name. -try removing the 3 from the class name; it''s not supposed to be a problem because it''s not the first character of the name but i feel like i''ve had a problem with numbers in class names before. --jacob Tomasz Kaye wrote:> I spoke too soon, i''m still stuck with the same problem (sorry). Perhaps > if i show how my model looks it''ll be obvious what i''m doing wrong; > > class Image < ActiveRecord::Base > > def destroy > s3delete > super > end > > def s3delete) > MiddleMan.new_worker( > :class => :s3_worker > ) > end > > end > > When i call destroy on an image model I''m getting the error: "NameError > (uninitialized constant S3Worker):" . which is to be expected i suppose. > How should i make S3Worker visible in this scope? > > thanks again. > > On Jan 15, 2007, at 7:51 PM, Joshua Bates wrote: > >> Just call work_thread on the worker. >> Something like.... >> >> def save_to_s3 >> worker.work_thread(:method => :save, :args => [args]) >> end >> >> def worker >> @worker ||= MiddleMan.worker(:s3) >> end >> >> If you need to pass the whole model to the worker, make sure to add >> include DRbUndumped in your model. >> >> On 1/15/07, *Tomasz Kaye* < tomasz at resourcestudio.nl >> <mailto:tomasz at resourcestudio.nl>> wrote: >> >> In short: how (if possible) would i go about arranging it so that i >> can instantiate a middleman and set a worker going from within a >> method in one of my models? or is this a weird thing to be wanting to >> do? ( >> >> My specific situation: I have an ''Image'' model in my application. An >> actual image file associated with the model is being stored on >> amazons s3 system. I''d like to use a worker to handle each s3 >> operation (eg. deleting the image from s3). The Image model seems the >> neatest place to set the worker going but I''m a little stumped as to >> how i should modify my model to enable the instantiation of middleman >> within it. >> >> thanks in advance for any pointers! >> >> (apologies in advance if this message gets posted twice; i think my >> previous attempt didn''t work) >> _______________________________________________ >> Backgroundrb-devel mailing list >> Backgroundrb-devel at rubyforge.org >> <mailto:Backgroundrb-devel at rubyforge.org> >> http://rubyforge.org/mailman/listinfo/backgroundrb-devel >> >> > > > ------------------------------------------------------------------------ > > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel
skaar
2007-Jan-16 17:08 UTC
[Backgroundrb-devel] Instantiating middleman and worker from inside a model?
give: MiddleMan.instance.new_worker :class => :s3_worker a try * Tomasz Kaye (tomasz at resourcestudio.nl) [070116 10:37]:> I spoke too soon, i''m still stuck with the same problem (sorry). Perhaps > if i show how my model looks it''ll be obvious what i''m doing wrong; > class Image < ActiveRecord::Base > > def destroy > s3delete > super > end > def s3delete) > MiddleMan.new_worker( > :class => :s3_worker > ) > end > end > When i call destroy on an image model I''m getting the error: "NameError > (uninitialized constant S3Worker):" . which is to be expected i suppose. > How should i make S3Worker visible in this scope? > thanks again. > On Jan 15, 2007, at 7:51 PM, Joshua Bates wrote: > > Just call work_thread on the worker. > Something like.... > > def save_to_s3 > worker.work_thread(:method => :save, :args => [args]) > end > > def worker > @worker ||= MiddleMan.worker(:s3) > end > > If you need to pass the whole model to the worker, make sure to add > include DRbUndumped in your model. > > On 1/15/07, Tomasz Kaye < [1]tomasz at resourcestudio.nl> wrote: > > In short: how (if possible) would i go about arranging it so that i > can instantiate a middleman and set a worker going from within a > method in one of my models? or is this a weird thing to be wanting to > do? ( > > My specific situation: I have an ''Image'' model in my application. An > actual image file associated with the model is being stored on > amazons s3 system. I''d like to use a worker to handle each s3 > operation (eg. deleting the image from s3). The Image model seems the > neatest place to set the worker going but I''m a little stumped as to > how i should modify my model to enable the instantiation of middleman > within it. > > thanks in advance for any pointers! > > (apologies in advance if this message gets posted twice; i think my > previous attempt didn''t work) > _______________________________________________ > Backgroundrb-devel mailing list > [2]Backgroundrb-devel at rubyforge.org > [3]http://rubyforge.org/mailman/listinfo/backgroundrb-devel > > References > > Visible links > 1. mailto:tomasz at resourcestudio.nl > 2. mailto:Backgroundrb-devel at rubyforge.org > 3. http://rubyforge.org/mailman/listinfo/backgroundrb-devel> _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel-- ---------------------------------------------------------------------- |\|\ where in the | s_u_b_s_t_r_u_c_t_i_o_n | | >=========== W.A.S.T.E. | genarratologies |/|/ (_) is the wisdom | skaar at waste.org ----------------------------------------------------------------------
Tomasz Kaye
2007-Jan-23 11:13 UTC
[Backgroundrb-devel] Instantiating middleman and worker from inside a model?
thats for all the suggestions and help! I think in the end it was a stray ''end'' that was causing the errors, and i was looking for something more complicated. apologies for not checking my code more thoroughly!