Bill Walton
2006-Oct-17 20:21 UTC
[Backgroundrb-devel] Session access interfers with other model access
Sorry to be such a bother but I''m not getting this.
I have two models: Emrec and Session (I''m using AR for session mgmt.)
In my
worker I can access the Emrec model and delete a record, AS LONG AS I
don''t
try to access the Session model. With the Session model access commented
out as below, the Emrec record gets deleted. If I uncomment those lines,
the Emrec record is _not_ deleted. Any idea what I''m doing wrong?
Thanks,
Bill
In my controller...
@session_id = session.session_id
session[:job_key] = MiddleMan.new_worker(:class => :foo_worker,
:args => {:emrec_id =>
@emrec.id,
:session_id =>
@session_id})
In my worker...
def do_work(args)
@time_remaining = 7
@emrec_id = args[:emrec_id]
#@session_rec = Session.find(:first,
# :conditions => ["sessid = ?",
args[:session_id]])
calculate_the_meaning_of_life(args)
Emrec.delete(@emrec_id)
end
Bill Walton
2006-Oct-17 20:52 UTC
[Backgroundrb-devel] Session access interfers with other modelaccess
Update... I explicitly generated a Session model and that made things a little better. I can uncomment the lines below and now the Emrec DOES get deleted. However, if I try to also delete the Session record, neither gets deleted. Any ideas what gives? Thanks, Bill ----- Original Message ----- From: "Bill Walton" <bill.walton at charter.net> To: "BackgroundRb" <backgroundrb-devel at rubyforge.org> Sent: Tuesday, October 17, 2006 3:21 PM Subject: [Backgroundrb-devel] Session access interfers with other modelaccess> Sorry to be such a bother but I''m not getting this. > > I have two models: Emrec and Session (I''m using AR for session mgmt.) In > my > worker I can access the Emrec model and delete a record, AS LONG AS I > don''t > try to access the Session model. With the Session model access commented > out as below, the Emrec record gets deleted. If I uncomment those lines, > the Emrec record is _not_ deleted. Any idea what I''m doing wrong? > > Thanks, > Bill > > > In my controller... > > @session_id = session.session_id > session[:job_key] = MiddleMan.new_worker(:class => :foo_worker, > :args => {:emrec_id => > @emrec.id, > :session_id => > @session_id}) > > > In my worker... > > def do_work(args) > @time_remaining = 7 > @emrec_id = args[:emrec_id] > > #@session_rec = Session.find(:first, > # :conditions => ["sessid = ?", > args[:session_id]]) > > calculate_the_meaning_of_life(args) > Emrec.delete(@emrec_id) > end > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >
Michael D''Auria
2006-Oct-17 21:13 UTC
[Backgroundrb-devel] Session access interfers with other modelaccess
Are there any logs we can look at? In dev mode we can see MySQL logs On 10/17/06, Bill Walton <bill.walton at charter.net> wrote:> > Update... > > I explicitly generated a Session model and that made things a little > better. > I can uncomment the lines below and now the Emrec DOES get deleted. > However, if I try to also delete the Session record, neither gets deleted. > Any ideas what gives? > > Thanks, > Bill > > ----- Original Message ----- > From: "Bill Walton" <bill.walton at charter.net> > To: "BackgroundRb" <backgroundrb-devel at rubyforge.org> > Sent: Tuesday, October 17, 2006 3:21 PM > Subject: [Backgroundrb-devel] Session access interfers with other > modelaccess > > > > Sorry to be such a bother but I''m not getting this. > > > > I have two models: Emrec and Session (I''m using AR for session > mgmt.) In > > my > > worker I can access the Emrec model and delete a record, AS LONG AS I > > don''t > > try to access the Session model. With the Session model access > commented > > out as below, the Emrec record gets deleted. If I uncomment those > lines, > > the Emrec record is _not_ deleted. Any idea what I''m doing wrong? > > > > Thanks, > > Bill > > > > > > In my controller... > > > > @session_id = session.session_id > > session[:job_key] = MiddleMan.new_worker(:class => :foo_worker, > > :args => {:emrec_id => > > @emrec.id, > > :session_id => > > @session_id}) > > > > > > In my worker... > > > > def do_work(args) > > @time_remaining = 7 > > @emrec_id = args[:emrec_id] > > > > #@session_rec = Session.find(:first, > > # :conditions => ["sessid = ?", > > args[:session_id]]) > > > > calculate_the_meaning_of_life(args) > > Emrec.delete(@emrec_id) > > end > > _______________________________________________ > > 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20061017/9ab43663/attachment.html
Bill Walton
2006-Oct-18 19:03 UTC
[Backgroundrb-devel] Session access interfers with other modelaccess
Sorry for the fat-fingered send earlier.
Further investigation reveals concrete evidence. Just not sure what it
means. Sure would appreciate any insight / suggestions. Code below.
I found that the backgroundrb.log was telling me it was encountering an
error in the worker, trying to do a delete on a nil id. What I''ve
found out
is this.
If I start a new browser (i.e., a new session) and point it to the app, the
find in the worker fails and so the delete of the session record fails.
Problem it, I can see the record (via MySQL-Front) in the table prior to the
worker attempt to find it. Why does the find fail?
If I restart the app (i.e., still using the same session id), the find in
the worker SUCCEEDS, the session record is deleted, and a new (empty)
session is created. Why does the find succeed this time? Is there
something different about the session record at this point (like something I
could _make_ happen)? There''s no _visible_ difference.
Any ideas at all what might be going on here? I''d be *real* happy to
send
along the view/layout and model if anybody''s willing to give it a quick
look.
TIA,
Bill
--------- Controller ------------
class CreateController < ApplicationController
def index
@emrec = Emrec.new
@emrec.last_updated_at = Time.now
@emrec.save
@session_id = session.session_id
session[:job_key] = MiddleMan.new_worker(:class => :foo_worker,
:args => {:emrec_id =>
@emrec.id,
:session_id =>
@session_id})
@session_rec_id = @session_id
end
def get_time_remaining
if request.xhr?
progress_percent =
MiddleMan.get_worker(session[:job_key]).time_remaining
render :update do |page|
page.call(''progressPercent'',
''clock'', progress_percent)
# commented-out to eliminate race condition on WinXP from debugging
# page.redirect_to(:action => ''done'') if
progress_percent <= 0
end
else
redirect_to :action => ''not_xhr''
end
end
def done
render :text => "Your FooWorker task has completed"
MiddleMan.delete_worker(session[:job_key])
end
end
----------- end Controller ------------
---------- worker -------------
class FooWorker < BackgrounDRb::Rails
attr_reader :time_remaining
def do_work(args)
@time_remaining = 15
@emrec_id = args[:emrec_id]
@session_id = args[:session_id]
@session_rec = Session.find(:first,
:conditions => ["sessid = ?",
@session_id])
calculate_the_meaning_of_life(args)
if !@session_rec.nil?
Session.delete(@session_rec.id)
end
Emrec.delete(@emrec_id)
end
def calculate_the_meaning_of_life(args)
while @time_remaining > 0
@time_remaining -= 1
sleep(1)
end
end
end
----- end worker ------
Bill Walton
2006-Oct-19 13:19 UTC
[Backgroundrb-devel] RESOLVED: Session access interfers with other model access
Bill Walton wrote:> > If I start a new browser (i.e., a new session) and > point it to the app, the find in the worker fails and > so the delete of the session record fails. Problem is, > I can see the record (via MySQL-Front) in the table > prior to the worker attempt to find it. Why does the > find fail?I still do not understand why I can see the record in the table via MySQL-Front but Rails / BackgrounDRb cannot find it, but I figured out how to fix the problem. Doing a session.update in the controller prior to the Middleman call somehow puts the record in a state where the find in the worker on the sessid field succeeds. Hope this helps someone in the future. If anybody can explain what''s going on with the session I''d be very interested to learn. Best regards, Bill
Ezra Zygmuntowicz
2006-Oct-19 15:51 UTC
[Backgroundrb-devel] RESOLVED: Session access interfers with other model access
On Oct 19, 2006, at 6:19 AM, Bill Walton wrote:> > Bill Walton wrote: >> >> If I start a new browser (i.e., a new session) and >> point it to the app, the find in the worker fails and >> so the delete of the session record fails. Problem is, >> I can see the record (via MySQL-Front) in the table >> prior to the worker attempt to find it. Why does the >> find fail? > > I still do not understand why I can see the record in the table via > MySQL-Front but Rails / BackgrounDRb cannot find it, but I figured > out how > to fix the problem. > > Doing a session.update in the controller prior to the Middleman > call somehow > puts the record in a state where the find in the worker on the > sessid field > succeeds. > > Hope this helps someone in the future. If anybody can explain > what''s going > on with the session I''d be very interested to learn. > > Best regards, > BillAhh good catch Bill. That makes total sense though. When you call the middleman from a rails action without doing the session.update, the session record is still in memory and not written to the db yet. update makes it write out the session into the db. Glad you got it working. Cheers- -- Ezra Zygmuntowicz -- Lead Rails Evangelist -- ez at engineyard.com -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273)
Bill Walton
2006-Oct-19 17:09 UTC
[Backgroundrb-devel] RESOLVED: Session access interfers with other model access
Hi Ezra, Ezra Zygmuntowicz wrote:> When you call the middleman from a rails action without doing the > session.update, the session record is still in memory and not written to > the db yet. update makes it write out the session into the db.That''s not what it looks like. What I mean is that I can _see_ the record in the database via MySQL-Front before the find is attempted. Unless I very much misunderstand the way MySQL-Front works, the record has, in fact, already been written to the db. Rails (or BackgrounDRb) just can''t retrieve it for some reason.> Glad you got it working.Thanks! I just wish I understood _why_ it''s working. Best regards, Bill