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