samuel at descolada.com
Thu Jul 12 22:38:34 UTC 2007
I wrote a quick hack of Python client for Gearman, and although it
will be completely rewritten I figure it's worth putting out there
since it doesn't seem that there are any other Python clients
available. The plan is to write a more durable and clean library
without the need for twisted when there's more time. I hope someone
can make some kind of use out of this at least.
Usage is best described by an example:
hosts = ["127.0.0.1:7003"]
worker = GearmanWorker(job_servers=hosts)
client = GearmanClient(job_servers=hosts)
d = client.do_task("__main__.TestWorker.echo", "test", "-",
on_success=lambda blah:sys.stdout.write("DONE: %s\n" % blah),
on_status=lambda num,den:sys.stdout.write("STATUS: %s/%s\n" %
print "ERROR: %s" % exc.type
print "CREATED: %s" % job.handle
# lambda res:sys.stdout.write("DONE: %s\n" % res),
do_task returns a deferred that gets called when the task gets created
(not when it completes) with the Job class instance for that task.
job.deferred is the actual deferred for the task and gets called when
the task completes. on_success is a shortcut so that you don't need to
have a callback on the task creation that adds a callback for the task
completion. (eeeks!) "task is created" means that the server sent back
a handle for the task.
As I said though, it's all quite messy. heh. My only use so far has
been to play around with Djabberd (which is why it was written) so I
wouldn't consider it tested by any stretch of the imagination.
More information about the Gearman