Is there something special I need to do to access session data in a worker? I''m using an AR session store. I''ve been working with Ezra''s tutorial, modifying it a little here and there to figure it out. So I changed the progress bar to a simple count-down in the worker which sends back the count to display in the view. No big deal. But if I try to access session data in the worker method, I get no count displayed in the view. Any ideas? Thanks, Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20061016/f5a1aa1e/attachment.html
Michael D''Auria
2006-Oct-16 22:21 UTC
[Backgroundrb-devel] accessing session data in worker
Do you have a code snippet to show? The Session model should be availible if you are loading rails. On 10/16/06, Bill Walton <bill.walton at charter.net> wrote:> > Is there something special I need to do to access session data in a > worker? > > I''m using an AR session store. I''ve been working with Ezra''s tutorial, > modifying it a little here and there to figure it out. So I changed the > progress bar to a simple count-down in the worker which sends back the count > to display in the view. No big deal. But if I try to access session data > in the worker method, I get no count displayed in the view. > > Any ideas? > > Thanks, > Bill > > > > _______________________________________________ > 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/20061016/7a150482/attachment.html
Ezra Zygmuntowicz
2006-Oct-17 00:22 UTC
[Backgroundrb-devel] accessing session data in worker
On Oct 16, 2006, at 2:55 PM, Bill Walton wrote:> Is there something special I need to do to access session data in a > worker? > > I''m using an AR session store. I''ve been working with Ezra''s > tutorial, modifying it a little here and there to figure it out. > So I changed the progress bar to a simple count-down in the worker > which sends back the count to display in the view. No big deal. > But if I try to access session data in the worker method, I get no > count displayed in the view. > > Any ideas? > > Thanks, > Bill > > > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-develThe session is not available in the workers. If you need a value from the session then you must pass it into the new_worker call ass :args Cheers- -- Ezra Zygmuntowicz -- Lead Rails Architect -- ez at engineyard.com -- Engine Yard, Serious Rails Hosting -- Reliability, Ease of Use, Scalability -- (866) 518-YARD (9273)
Hi Ezra, Ezra Zygmuntowicz wrote:> The session is not available in the workers.Thanks for clearing that up for me! So the data ''inside'' the session record is not available, but the session record IS? I''m using BackgroundRB to do session cleanup for abandoned sessions. I''m thinking that I can pass the session id to the worker and then, inside the worker, retrieve and delete that record with something like session_record = Session.find(:first, :conditions => ["sessid = ?", passed_in_session_id]) session_record.destroy Is that right? Or do I need to do something special to access that record? Thanks, Bill
Michael D''Auria
2006-Oct-17 14:42 UTC
[Backgroundrb-devel] accessing session data in worker
I was accessing the Session model directly from within a worker and it was working: class ClearSessionsWorker < BackgrounDRb::Rails repeat_every 7.minutes first_run Time.now def do_work(args) Session.destroy_all(["updated_at < ?", 20.minute.ago ]) ::BackgrounDRb::MiddleMan.instance.delete_worker @_job_key end end I just wasn''t cleaning the workers up properly, but it was cleaning out sessions as it should... On 10/17/06, Bill Walton <bill.walton at charter.net> wrote:> > Hi Ezra, > > Ezra Zygmuntowicz wrote: > > > The session is not available in the workers. > > Thanks for clearing that up for me! So the data ''inside'' the session > record > is not available, but the session record IS? I''m using BackgroundRB to do > session cleanup for abandoned sessions. I''m thinking that I can pass the > session id to the worker and then, inside the worker, retrieve and delete > that record with something like > > session_record = Session.find(:first, :conditions => ["sessid = ?", > passed_in_session_id]) > session_record.destroy > > Is that right? Or do I need to do something special to access that > record? > > Thanks, > Bill > _______________________________________________ > 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/20061017/d7e9d4a2/attachment.html
Hi Michael, Michael D''Auria wrote:> I was accessing the Session model directly > from within a worker and it was working:I don''t seem to be able to access my models at all. I''ve got two AR models in this little sandbox app: Session and Emrec. I thought I''d start with the Emrec model (haven''t tried to access the Session model yet). In the controller, before starting up the worker, I create an Emrec. In the worker, I want to delete it. I was trying to pass in the id of the record I want but couldn''t get that to work. I figured it was a problem with how I was trying to access the record id, so I tried to hardcode the delete. My worker looks like... ----------- worker --------- class FooWorker < BackgrounDRb::Rails attr_reader :time_remaining def do_work(args) @time_remaining = 7 calculate_the_meaning_of_life(args) end def calculate_the_meaning_of_life(args) while @time_remaining > 0 # calculations here @time_remaining -= 1 sleep(1) end Emrec.delete(1) end end --------- end of worker --------- The emrec is not getting deleted. Any idea what I''m doing wrong here? Also, assuming I get the hardcoded version working, what''s the syntax for accessing the values passed in the args hash? Thanks, Bill
Ezra Zygmuntowicz
2006-Oct-17 17:12 UTC
[Backgroundrb-devel] accessing session data in worker
Ahh ok I misunderstood you then. I thought you were trying to use session[:foo] from within a worker my bad. -Ezra On Oct 17, 2006, at 7:42 AM, Michael D''Auria wrote:> I was accessing the Session model directly from within a worker and > it was working: > > class ClearSessionsWorker < BackgrounDRb::Rails > > repeat_every 7.minutes > first_run Time.now > > def do_work(args) > Session.destroy_all(["updated_at < ?", 20.minute.ago ]) > > ::BackgrounDRb::MiddleMan.instance.delete_worker @_job_key > end > end > > I just wasn''t cleaning the workers up properly, but it was cleaning > out sessions as it should... > > > On 10/17/06, Bill Walton <bill.walton at charter.net> wrote: Hi Ezra, > > Ezra Zygmuntowicz wrote: > > > The session is not available in the workers. > > Thanks for clearing that up for me! So the data ''inside'' the > session record > is not available, but the session record IS? I''m using > BackgroundRB to do > session cleanup for abandoned sessions. I''m thinking that I can > pass the > session id to the worker and then, inside the worker, retrieve and > delete > that record with something like > > session_record = Session.find(:first, :conditions => ["sessid = ?", > passed_in_session_id]) > session_record.destroy > > Is that right? Or do I need to do something special to access that > record? > > Thanks, > Bill > _______________________________________________ > Backgroundrb-devel mailing list > 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-- Ezra Zygmuntowicz -- Lead Rails Evangelist -- ez at engineyard.com -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273)