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