1 | import sets |
---|
2 | import logging |
---|
3 | from Products.QueueCatalog.CatalogEventQueue import CatalogEventQueue, EVENT_TYPES, ADDED_EVENTS |
---|
4 | from Products.QueueCatalog.CatalogEventQueue import ADDED, CHANGED, CHANGED_ADDED, REMOVED |
---|
5 | from Products.QueueCatalog.CatalogEventQueue import SAFE_POLICY, ALTERNATIVE_POLICY |
---|
6 | from Products.QueueCatalog.QueueCatalog import cataloged |
---|
7 | from ZODB.POSException import ConflictError |
---|
8 | from ZEO.Exceptions import ClientDisconnected |
---|
9 | logger = logging.getLogger('event.QueueCatalog') |
---|
10 | |
---|
11 | def _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 |
---|
58 | from Products.QueueCatalog.QueueCatalog import QueueCatalog |
---|
59 | QueueCatalog._process_queue = _process_queue |
---|