[Backgroundrb-devel] How to obtain task progress for long-running methods

Jim Nicholson jnicholson at skarven.net
Fri Nov 7 11:04:14 EST 2008


Hmm... I'm using the git version of backgroundrb, and currently up-to-
date with the repository; I don't have an "ask_worker" method; I have
"ask_result." Maybe I should be asking: where can I obtain the version
of Backgroundrb that's covered in "The Rails Way," because it seems the
API has changed significantly.

Anyway, I'm creating new workers via something like

MiddleMan.new_worker(:worker => :foobar_worker, :worker_key => 'some key
', :data => {:arguments => values})

The worker is coded to such that the process logic is called inside the
create method, and it posts progress via cache[worker_key]

  def create(args = nil)
	run_my_process(args)
  end

  def run_my_process(args)
    cache[worker_key] = {}
    ... do stuff
    cache[worker_key][:progress] = 25
    ... do more stuff
    cache[worker_key][:progress] = 50
    ... etc
  end

While this runs, I can see the worker chugging away (because it logs as
it runs,) but if I call

MiddleMan.worker(:foobar_worker).ask_result('some key') 

while it is running, I get nil.

Prior to this, I had a prior version of the worker that stayed in
menory. To use that one, I invoked the process via

MiddleMan.worker(:foobar_worker).async_run_my_process('some key')

The only difference in the coding of the worker for that version was
that the cache key was job_key rather than worker_key. Calling
ask_results('some key') produced nil until the task was completed, at
which point it contained my end-state results.





On Fri, 2008-11-07 at 12:57 +1300, Kieran P wrote:
> Hello Jim,
> 
> We had the same problem when we upgraded Backgroundrb. The solution
> provided by hemant was to add these line in your backgroundrb.yml
> config
> 
> :backgroundrb:
>   :result_storage: memcache
> 
> :memcache: "127.0.0.1:11211"
> 
> 
> With that in place, ask_worker should start working.
> 
> Regards
> Kieran
> 
> 
> On Fri, Nov 7, 2008 at 5:13 AM, Jim Nicholson <jnicholson at skarven.net>
> wrote:
>         We've used previous versions of backgroundrb to handle long-
>         running
>         tasks, like ingesting large XML uploads into the database. In
>         the
>         previous API, we could set accessors on workers and use them
>         to provide
>         status and progress indicators as the main worker method
>         churned away.
>         
>         With the recent API changes, I can't see how this sort of
>         thing would be
>         done. It seems that calls to "ask_results" while a method is
>         running
>         always return nil, rather than whatever the current contents
>         of the
>         cache are.
>         
>         Is there some mechanism I'm missing for doing this sort of
>         thing? I can
>         see the usefulness of the new API and support for clustering,
>         etc, but
>         if I can't give the user feedback on an active worker's
>         progress, I'm
>         going to have to go back to the previous incarnation of
>         backgroundrb.
>         
>         
>         
>         _______________________________________________
>         Backgroundrb-devel mailing list
>         Backgroundrb-devel at rubyforge.org
>         http://rubyforge.org/mailman/listinfo/backgroundrb-devel
> 



More information about the Backgroundrb-devel mailing list