pythonqueueplone

Remove all jobs from plone.app.async queue


I have a lot of jobs in the queue and I just want to empty it, instead of waiting for them. So I managed to access pdb and this is what I tried:

from zope.component import queryUtility
from plone.app.async.interfaces import IAsyncService

service = queryUtility(IAsyncService)
(Pdb) service
<plone.app.async.service.AsyncService object at 0x...>

queues = service.getQueues()
queues
<zc.async.queue.Queues object at 0x...>

vars(queues)
{'_len': <BTrees.Length.Length object at 0x...>, '_data': <BTrees.OOBTree.OOBTree object at 0x...>}

(Pdb) queues.values()
[<zc.async.queue.Queue object at 0x...>]

queue = queues.values()[0]
(Pdb) queue
<zc.async.queue.Queue object at 0x...>

dir(queue)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__getstate__', '__hash__', '__implemented__', '__init__', '__iter__', '__len__', '__module__', '__new__', '__nonzero__', '__parent__', '__providedBy__', '__provides__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__slotnames__', '__str__', '__subclasshook__', '__weakref__', '_held', '_iter', '_length', '_p_activate', '_p_changed', '_p_deactivate', '_p_delattr', '_p_estimated_size', '_p_getattr', '_p_invalidate', '_p_jar', '_p_mtime', '_p_oid', '_p_serial', '_p_setattr', '_p_state', '_putback_queue', '_queue', '_z_parent__', 'claim', 'dispatchers', 'name', 'parent', 'pull', 'put', 'putBack', 'quotas', 'remove']

(Pdb) vars(queue)
{'name': '', 'parent': <zc.async.queue.Queues object at 0x...>, '_held': <BTrees.OOBTree.OOBTree object at 0x...>, 'quotas': <zc.async.queue.Quotas object at 0x...>, 'dispatchers': <zc.async.queue.Dispatchers object at 0x...>, '_length': <BTrees.Length.Length object at 0x...>, '_queue': <zc.queue._queue.CompositeQueue object at 0x...>, '_putback_queue': <zc.queue._queue.CompositeQueue object at 0x...>}

qu = queue._queue
(Pdb) qu
<zc.queue._queue.CompositeQueue object at 0x...>

dir(qu)
dir(qu)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__getstate__', '__hash__', '__implemented__', '__init__', '__iter__', '__len__', '__module__', '__new__', '__nonzero__', '__providedBy__', '__provides__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__slotnames__', '__str__', '__subclasshook__', '__weakref__', '_data', '_p_activate', '_p_changed', '_p_deactivate', '_p_delattr', '_p_estimated_size', '_p_getattr', '_p_invalidate', '_p_jar', '_p_mtime', '_p_oid', '_p_resolveConflict', '_p_serial', '_p_setattr', '_p_state', 'compositeSize', 'pull', 'put', 'subfactory']

qu.clear()
*** AttributeError: 'CompositeQueue' object has no attribute 'clear'

len(queue)
64252

queue.clear()
*** AttributeError: 'Queue' object has no attribute 'clear'

I feel that I am so close, but it's annoying I can't find how to get rid of these 64000+ items in the queue. Please help.


Solution

  • You can use eea.async.manager

    This add-on will add a control panel entry in Site Setup called Async Manager

    Here you will be able to cleanup dead async dispatchers, queued jobs, completed jobs, etc.

    Or, you can check the code, and do it yourself via pdb.

    Click on the jobs' numbers to see details.

    You can show more than 20 results per page, by passing the b_size param in URL like:

    `@@async-controlpanel-jobs?queue=&b_start:int=0&b_size:int=1000`