Commit 6e895eeb authored by Sebastien Robin's avatar Sebastien Robin

check if we have sql methods before calling them

make ramqueue working with several cmf site


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@719 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cffc1790
...@@ -36,57 +36,61 @@ class RAMQueue(Queue): ...@@ -36,57 +36,61 @@ class RAMQueue(Queue):
""" """
def __init__(self): def __init__(self):
Queue.__init__(self) Queue.__init__(self)
self.queue = [] self.queue_dict = {}
self.last_uid = 0 self.last_uid = 0
def getQueue(self, activity_tool):
path = activity_tool.getPhysicalPath()
if not self.queue_dict.has_key(path):
self.queue_dict[path] = []
return self.queue_dict[path]
def finishQueueMessage(self, activity_tool, m): def finishQueueMessage(self, activity_tool, m):
if m.is_registered: if m.is_registered:
# XXX - Some lock is required on this section # XXX - Some lock is required on this section
self.last_uid = self.last_uid + 1 self.last_uid = self.last_uid + 1
m.uid = self.last_uid m.uid = self.last_uid
self.queue.append(m) self.getQueue(activity_tool).append(m)
def finishDeleteMessage(self, activity_tool, m): def finishDeleteMessage(self, activity_tool, m):
i = 0 i = 0
for my_message in self.queue: queue = self.getQueue(activity_tool)
for my_message in queue:
if my_message.uid == m.uid: if my_message.uid == m.uid:
del self.queue[i] del queue[i]
return return
i = i + 1 i = i + 1
def dequeueMessage(self, activity_tool, processing_node): def dequeueMessage(self, activity_tool, processing_node):
if len(self.queue) is 0: if len(self.getQueue(activity_tool)) is 0:
return 1 # Go to sleep return 1 # Go to sleep
m = self.queue[0] m = self.getQueue(activity_tool)[0]
activity_tool.invoke(m) activity_tool.invoke(m)
self.deleteMessage(activity_tool, m) self.deleteMessage(activity_tool, m)
return 0 # Keep on ticking return 0 # Keep on ticking
def hasActivity(self, activity_tool, object, **kw): def hasActivity(self, activity_tool, object, **kw):
if object is not None: object_path = object.getPhysicalPath()
object_path = object.getPhysicalPath() for m in self.getQueue(activity_tool):
for m in self.queue: if m.object_path == object_path:
if list(m.object_path) == list(object_path): return 1
return 1
else:
return 1 # Default behaviour if no object specified is to return 1 until active_process implemented
return 0 return 0
def flush(self, activity_tool, object_path, invoke=0, method_id=None, **kw): def flush(self, activity_tool, object_path, invoke=0, method_id=None, **kw):
# Parse each message in registered # Parse each message in registered
for m in activity_tool.getRegisteredMessageList(self): for m in activity_tool.getRegisteredMessageList(self):
if list(m.object_path) == list(object_path) and (method_id is None or method_id == m.method_id): if object_path == m.object_path and (method_id is None or method_id == m.method_id):
if invoke: activity_tool.invoke(m) if invoke: activity_tool.invoke(m)
activity_tool.unregisterMessage(self, m) activity_tool.unregisterMessage(self, m)
# Parse each message in queue # Parse each message in queue
for m in self.queue: for m in self.getQueue(activity_tool):
if list(m.object_path) == list(object_path) and (method_id is None or method_id == m.method_id): if object_path == m.object_path and (method_id is None or method_id == m.method_id):
if invoke: activity_tool.invoke(m) if invoke: activity_tool.invoke(m)
self.deleteMessage(activity_tool, m) self.deleteMessage(activity_tool, m)
def getMessageList(self, activity_tool, processing_node=None): def getMessageList(self, activity_tool, processing_node=None):
new_queue = [] new_queue = []
for m in self.queue: for m in self.getQueue(activity_tool):
m.processing_node = 1 m.processing_node = 1
m.priority = 0 m.priority = 0
new_queue.append(m) new_queue.append(m)
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment