[Backgroundrb-devel] register_status for excess thread_pool?

Roggie Boone rogboone at yahoo.com
Fri May 9 09:15:57 EDT 2008


Hi,

Newbie here.  I've got a worker (for generating PDF reports) that
uses the "thread_pool" to allow processing multiple reports 
simultaneously and queue up any requests that exceed the thread
pool (pool_size = 10 currently).

  def process_pdf(user)
      thread_pool.defer(user) do |user|
        makepdf(user)
      end
  end

My question is:  I use a mutex to handle synchronizing the
register_status.  This works fine:

def makepdf(user)
      txt = user.to_s + " started"
      save_status(user, :progress, txt)
      do_report(user)      
      txt = user.to_s + " ended"
      save_status(user, :progress, txt) 
  end

  def save_status(user_id,key,data)
    @status_mutex.synchronize do
      @worker_status[user_id] = { :key => key, :data => data}
    end
    register_status(@worker_status)
  end

However, if more than 10 requests are submitted to the worker
at a time, those in excess of 10 are queued and thus never
get assigned a status in register_status.  So, in my Rails/ajax
view, I have no "status" to display while the user waits.
I read that one shouldn't use the register_status inside the
thread_pool.defer block.  Is there an alternate way to 
show a "pending" status to requests that have been deferred
due to exceeding the thread pool?

Thanks,
Rog

       
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20080509/6ac6a838/attachment.html>


More information about the Backgroundrb-devel mailing list