source: WAeUP_SRP/base/PatchQueueCatalogProcessQueue.py @ 2237

Last change on this file since 2237 was 2235, checked in by joachim, 17 years ago

fix for #310 new site can now be instanciated

  • Property svn:keywords set to Id
File size: 2.7 KB
RevLine 
[1930]1import sets
[2074]2import logging
[1934]3from Products.QueueCatalog.CatalogEventQueue import CatalogEventQueue, EVENT_TYPES, ADDED_EVENTS
4from Products.QueueCatalog.CatalogEventQueue import ADDED, CHANGED, CHANGED_ADDED, REMOVED
5from Products.QueueCatalog.CatalogEventQueue import SAFE_POLICY, ALTERNATIVE_POLICY
6from Products.QueueCatalog.QueueCatalog import cataloged
[2073]7from ZODB.POSException import ConflictError
8from ZEO.Exceptions import ClientDisconnected
[2074]9logger = logging.getLogger('event.QueueCatalog')
[1930]10
[2235]11def __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]20def _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]67from Products.QueueCatalog.QueueCatalog import QueueCatalog
[2235]68QueueCatalog.__init__ = __init__
[1926]69QueueCatalog._process_queue = _process_queue
[2235]70
Note: See TracBrowser for help on using the repository browser.