source: WAeUP_SRP/trunk_not_used/PatchQueueCatalogProcessQueue.py @ 3330

Last change on this file since 3330 was 2079, checked in by joachim, 17 years ago

exceptions enabled

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1import sets
2import logging
3from Products.QueueCatalog.CatalogEventQueue import CatalogEventQueue, EVENT_TYPES, ADDED_EVENTS
4from Products.QueueCatalog.CatalogEventQueue import ADDED, CHANGED, CHANGED_ADDED, REMOVED
5from Products.QueueCatalog.CatalogEventQueue import SAFE_POLICY, ALTERNATIVE_POLICY
6from Products.QueueCatalog.QueueCatalog import cataloged
7from ZODB.POSException import ConflictError
8from ZEO.Exceptions import ClientDisconnected
9logger = logging.getLogger('event.QueueCatalog')
10
11def _process_queue(self, queue, limit):
12    """Process a single queue"""
13    catalog = self.getZCatalog()
14
15    if self.getProcessAllIndexes():
16        #idxs = None
17        idxs = catalog.indexes()
18    else:
19        cat_indexes = sets.Set(catalog.indexes())
20        immediate_indexes = sets.Set(self._immediate_indexes)
21        if not immediate_indexes or immediate_indexes==cat_indexes:
22            idxs = catalog.indexes() # do all of 'em
23        else:
24            idxs = list(cat_indexes - immediate_indexes)
25    events = queue.process(limit)
26    count = 0
27
28    for uid, (t, event) in events.items():
29        if event is REMOVED:
30            try:
31                if cataloged(catalog, uid):
32                    catalog.uncatalog_object(uid)
33            except (ConflictError, ClientDisconnected):
34                logger.error('conflict-error uncataloging object', exc_info=True)
35            except:
36                logger.error('error uncataloging object', exc_info=True)
37        else:
38            # add or change
39            if event is CHANGED and not cataloged(catalog, uid):
40                continue
41            # Note that the uid may be relative to the catalog.
42            obj = catalog.unrestrictedTraverse(uid, None)
43            if obj is not None:
44                immediate_metadata = self.getImmediateMetadataUpdate()
45                try:
46                    catalog.catalog_object(
47                        obj, uid, idxs=idxs,
48                        update_metadata=not immediate_metadata)
49                except (ConflictError, ClientDisconnected):
50                    logger.error('conflict-error uncataloging object', exc_info=True)
51                    #raise
52                except:
53                    logger.error('error cataloging object', exc_info=True)
54
55        count = count + 1
56
57    return count
58from Products.QueueCatalog.QueueCatalog import QueueCatalog
59QueueCatalog._process_queue = _process_queue
Note: See TracBrowser for help on using the repository browser.