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 __init__(self, |
---|
12 | buckets=1009, |
---|
13 | conflict_policy=SAFE_POLICY, |
---|
14 | location = "portal_catalog_real"): |
---|
15 | self._buckets = buckets |
---|
16 | self._conflict_policy = conflict_policy |
---|
17 | self._clearQueues() |
---|
18 | self._location = location |
---|
19 | |
---|
20 | def _process_queue(self, queue, limit): |
---|
21 | """Process a single queue""" |
---|
22 | catalog = self.getZCatalog() |
---|
23 | |
---|
24 | if self.getProcessAllIndexes(): |
---|
25 | #idxs = None |
---|
26 | idxs = catalog.indexes() |
---|
27 | else: |
---|
28 | cat_indexes = sets.Set(catalog.indexes()) |
---|
29 | immediate_indexes = sets.Set(self._immediate_indexes) |
---|
30 | if not immediate_indexes or immediate_indexes==cat_indexes: |
---|
31 | idxs = catalog.indexes() # do all of 'em |
---|
32 | else: |
---|
33 | idxs = list(cat_indexes - immediate_indexes) |
---|
34 | events = queue.process(limit) |
---|
35 | count = 0 |
---|
36 | |
---|
37 | for uid, (t, event) in events.items(): |
---|
38 | if event is REMOVED: |
---|
39 | try: |
---|
40 | if cataloged(catalog, uid): |
---|
41 | catalog.uncatalog_object(uid) |
---|
42 | except (ConflictError, ClientDisconnected): |
---|
43 | logger.error('conflict-error uncataloging object', exc_info=True) |
---|
44 | except: |
---|
45 | logger.error('error uncataloging object', exc_info=True) |
---|
46 | else: |
---|
47 | # add or change |
---|
48 | if event is CHANGED and not cataloged(catalog, uid): |
---|
49 | continue |
---|
50 | # Note that the uid may be relative to the catalog. |
---|
51 | obj = catalog.unrestrictedTraverse(uid, None) |
---|
52 | if obj is not None: |
---|
53 | immediate_metadata = self.getImmediateMetadataUpdate() |
---|
54 | try: |
---|
55 | catalog.catalog_object( |
---|
56 | obj, uid, idxs=idxs, |
---|
57 | update_metadata=not immediate_metadata) |
---|
58 | except (ConflictError, ClientDisconnected): |
---|
59 | logger.error('conflict-error uncataloging object', exc_info=True) |
---|
60 | #raise |
---|
61 | except: |
---|
62 | logger.error('error cataloging object', exc_info=True) |
---|
63 | |
---|
64 | count = count + 1 |
---|
65 | |
---|
66 | return count |
---|
67 | from Products.QueueCatalog.QueueCatalog import QueueCatalog |
---|
68 | QueueCatalog.__init__ = __init__ |
---|
69 | QueueCatalog._process_queue = _process_queue |
---|
70 | |
---|