[Backgroundrb-devel] register_status for excess thread_pool?

Stevie Clifton stevie at slowbicycle.com
Fri May 9 09:31:28 EDT 2008


Hey Roggie,

If I'm reading your code correctly, the simplest way would just be to
call your save_status method before thread_pool.  That way you would
guarantee that each pdf job would start out with a "pending" state
that would change only when there's a free thread to handle that job.

def process_pdf(user)
  save_status(user, :progress, "#{user} pending")
  thread_pool.defer(user) do |user|
    makepdf(user)
  end
end


>

On Fri, May 9, 2008 at 9:15 AM, Roggie Boone <rogboone at yahoo.com> wrote:
> 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.
> _______________________________________________
> Backgroundrb-devel mailing list
> Backgroundrb-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/backgroundrb-devel
>


More information about the Backgroundrb-devel mailing list