[1930] | 1 | import sets |
---|
[2074] | 2 | import logging |
---|
[1934] | 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 |
---|
[2073] | 7 | from ZODB.POSException import ConflictError |
---|
| 8 | from ZEO.Exceptions import ClientDisconnected |
---|
[2074] | 9 | logger = logging.getLogger('event.QueueCatalog') |
---|
[1930] | 10 | |
---|
[2235] | 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 | |
---|
[1926] | 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) |
---|
[2079] | 42 | except (ConflictError, ClientDisconnected): |
---|
| 43 | logger.error('conflict-error uncataloging object', exc_info=True) |
---|
[1926] | 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) |
---|
[2079] | 58 | except (ConflictError, ClientDisconnected): |
---|
| 59 | logger.error('conflict-error uncataloging object', exc_info=True) |
---|
| 60 | #raise |
---|
[1926] | 61 | except: |
---|
| 62 | logger.error('error cataloging object', exc_info=True) |
---|
| 63 | |
---|
| 64 | count = count + 1 |
---|
| 65 | |
---|
| 66 | return count |
---|
[1934] | 67 | from Products.QueueCatalog.QueueCatalog import QueueCatalog |
---|
[2235] | 68 | QueueCatalog.__init__ = __init__ |
---|
[1926] | 69 | QueueCatalog._process_queue = _process_queue |
---|
[2235] | 70 | |
---|