[Backgroundrb-devel] Session access interfers with other modelaccess

Bill Walton bill.walton at charter.net
Wed Oct 18 15:03:22 EDT 2006


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 ------






More information about the Backgroundrb-devel mailing list