[Grok-dev] Re: Triggering recurring events and executing tasks in the "background"

Gary Poster gary at zope.com
Thu Apr 10 07:41:22 EDT 2008


On Apr 10, 2008, at 5:08 AM, Malthe Borch wrote:
> Gary Poster wrote:
>> FWIW, I just released 1.0 of zc.async and would appreciate feedback.
>
> This is very interesting.
>
> I've recently put together z3c.indexing.dispatch with preliminary  
> support for Xapian. It would be interesting to couple the two to get  
> asynchronous content indexing.
>
> With ZCatalog I think it's difficult to meet the requirement of a  
> picklable callable, at least in a Zope 2-context. I'm not sure what  
> innards are.

Well, if I understand your goal, the way to handle this is to use the  
closure-like ability of the Job.

Define a function in a module somewhere; module-level functions are  
picklable.  Have it expect an argument of the ZCatalog (or whatever is  
appropriate...).  Let's call the callable  
``Zope.Products.MyProduct.perform_index`` and the instance we'll index  
``catalog``.  Use something like this.

queue = zc.async.interfaces.IQueue(context) # or get the desired queue  
another way...
queue.put(zc.async.job.Job(Zope.Products.MyProduct.perform_index,  
catalog))

Now the job that will be performed asynchronously will be to call

Zope.Products.MyProduct.perform_index(catalog)

All the functionality except for the zc.z3monitor plugins should work  
fine for Zope 2, I would expect.

Gary


More information about the Grok-dev mailing list