Waiting for a task in another thread?

15 views
Skip to first unread message

Logan Bowers

unread,
Jul 28, 2008, 6:49:40 PM7/28/08
to gea...@googlegroups.com
Hello all,

I'm considering using Gearman for our asynchronous infrastructure
needs, however, I'm looking for a particular piece of functionality
that I haven't found in the docs: waiting on a task from another
process. Essentially, I want to kick off an asynchronous task during
one HTTP request (in process A), and then at some point in the future
wait for its completion during another HTTP request (in process B).
It looks like both the Ruby and Perl interfaces only expose waiting on
a taskset object you (the process) create. Is this correct?

Is there some way to get a global key to a taskset and use it to wait
for its completion in a process from which it didn't originate?
Thanks!

Joe Stump

unread,
Jul 28, 2008, 6:56:59 PM7/28/08
to gea...@googlegroups.com

We do this in Digg's submission process. What we do is set a key in
Memcached that gets set when you run the initial background job in
process A (say the key is 'crawl.098707097809708970987098709', which
is a unique key for the URL being submitted). We then flip over to an
intermediary page that looks like those pages when you search
Travelocity that says "We're digging through your results ..." that,
via an AJAX endpoint pings that Memcached key periodically. If the key
is empty we wait. If it's not we move to the next page.

There is no mechanism in Gearman itself for this. Once an asynchronous
background job is completed it disappears completely from the queue
and, since nothing is waiting on the other end for the results,
there's nothing you can do about that. As a result Memcache works
great as an intermediary.

Hope that helps.

--Joe

Justin Azoff

unread,
Jul 30, 2008, 10:38:51 PM7/30/08
to gearman
Tasks have handles, and there is a get_status method you can call with
the handle to get the status of the job.
For a taskset, calling get_status for each of the handles should
work...

--
- Justin
Reply all
Reply to author
Forward
0 new messages