Running Plone entrants asynchronously

When using Plone 4, I successfully created a subscriber event for additional processing while saving a custom content type. I did this using the interface Products.Archetypes.interfaces.IObjectInitializedEvent.

configure.zcml

<subscriber 
        for="mycustom.product.interfaces.IRepositoryItem
             Products.Archetypes.interfaces.IObjectInitializedEvent"
        handler=".subscribers.notifyCreatedRepositoryItem"
   /> 

subscribers.py

def notifyCreatedRepositoryItem(repositoryitem, event):
    """
    This gets called on IObjectInitializedEvent - which occurs when a new object is created.
    """ 
    my custom processing goes here. Should be asynchronous

However, additional processing can sometimes take too much time, and I was wondering if there is a way to run it in the background, that is, asynchronously.

Is it possible to trigger subscriber events asynchronously, for example, when you save an object?

+5
source share
2 answers

Not out of the box. You need to add asynch support for your environment.

plone.app.async; ZEO , , . , .

, , .

, :

from plone.app.async.interfaces import IAsyncService

async = getUtility(IAsyncService)
async.queueJob(an_async_task, someobject, arg1_value, arg2_value)

:

def an_async_task(someobject, arg1, arg2):
    # do something with someobject

someobject - ZODB. IAsyncService.queueJob , , . .

async, , .

+6

, collective.taskqueue , ( plone.app.async).

PyPI , , redis , .

+1

All Articles