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):
"""
def __init__(self):
Queue.__init__(self)
self.queue = []
self.queue_dict = {}
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):
if m.is_registered:
# XXX - Some lock is required on this section
self.last_uid = self.last_uid + 1
m.uid = self.last_uid
self.queue.append(m)
self.getQueue(activity_tool).append(m)
def finishDeleteMessage(self, activity_tool, m):
i = 0
for my_message in self.queue:
queue = self.getQueue(activity_tool)
for my_message in queue:
if my_message.uid == m.uid:
del self.queue[i]
del queue[i]
return
i = i + 1
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
m = self.queue[0]
m = self.getQueue(activity_tool)[0]
activity_tool.invoke(m)
self.deleteMessage(activity_tool, m)
return 0 # Keep on ticking
def hasActivity(self, activity_tool, object, **kw):
if object is not None:
object_path = object.getPhysicalPath()
for m in self.queue:
if list(m.object_path) == list(object_path):
for m in self.getQueue(activity_tool):
if m.object_path == object_path:
return 1
else:
return 1 # Default behaviour if no object specified is to return 1 until active_process implemented
return 0
def flush(self, activity_tool, object_path, invoke=0, method_id=None, **kw):
# Parse each message in registered
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)
activity_tool.unregisterMessage(self, m)
# Parse each message in queue
for m in self.queue:
if list(m.object_path) == list(object_path) and (method_id is None or method_id == m.method_id):
for m in self.getQueue(activity_tool):
if object_path == m.object_path and (method_id is None or method_id == m.method_id):
if invoke: activity_tool.invoke(m)
self.deleteMessage(activity_tool, m)
def getMessageList(self, activity_tool, processing_node=None):
new_queue = []
for m in self.queue:
for m in self.getQueue(activity_tool):
m.processing_node = 1
m.priority = 0
new_queue.append(m)
......
......@@ -94,6 +94,7 @@ class SQLDict(RAMDict):
# Queue semantic
def dequeueMessage(self, activity_tool, processing_node):
if hasattr(activity_tool,'SQLDict_readMessageList'):
priority = random.choice(priority_weight)
# Try to find a message at given priority level
result = activity_tool.SQLDict_readMessage(processing_node=processing_node, priority=priority)
......@@ -160,6 +161,7 @@ class SQLDict(RAMDict):
return 1
def hasActivity(self, activity_tool, object, **kw):
if hasattr(activity_tool,'SQLDict_readMessageList'):
if object is not None:
my_object_path = '/'.join(object.getPhysicalPath())
result = activity_tool.SQLDict_hasMessage(path=my_object_path, **kw)
......@@ -184,6 +186,7 @@ class SQLDict(RAMDict):
path = '/'.join(object_path)
# LOG('Flush', 0, str((path, invoke, method_id)))
method_dict = {}
if hasattr(activity_tool,'SQLDict_readMessageList'):
# Parse each message in registered
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):
......@@ -235,6 +238,7 @@ class SQLDict(RAMDict):
def getMessageList(self, activity_tool, processing_node=None):
# YO: reading all lines might cause a deadlock
message_list = []
if hasattr(activity_tool,'SQLDict_readMessageList'):
result = activity_tool.SQLDict_readMessageList(path=None, method_id=None, processing_node=None)
for line in result:
m = self.loadMessage(line.message, uid = line.uid)
......@@ -245,6 +249,7 @@ class SQLDict(RAMDict):
def distribute(self, activity_tool, node_count):
processing_node = 1
if hasattr(activity_tool,'SQLDict_readMessageList'):
result = activity_tool.SQLDict_readMessageList(path=None, method_id=None, processing_node = -1) # Only assign non assigned messages
get_transaction().commit() # Release locks before starting a potentially long calculation
path_dict = {}
......
......@@ -65,6 +65,7 @@ class SQLQueue(RAMQueue):
activity_tool.SQLQueue_delMessage(uid = m.uid)
def dequeueMessage(self, activity_tool, processing_node):
if hasattr(activity_tool,'SQLQueue_readMessageList'):
priority = random.choice(priority_weight)
# Try to find a message at given priority level
result = activity_tool.SQLQueue_readMessage(processing_node=processing_node, priority=priority)
......@@ -114,6 +115,7 @@ class SQLQueue(RAMQueue):
return 1
def hasActivity(self, activity_tool, object, **kw):
if hasattr(activity_tool,'SQLQueue_readMessageList'):
if object is not None:
my_object_path = '/'.join(object.getPhysicalPath())
result = activity_tool.SQLQueue_hasMessage(path=my_object_path, **kw)
......@@ -135,6 +137,7 @@ class SQLQueue(RAMQueue):
NOTE: commiting is very likely nonsenses here. We should just avoid to flush as much as possible
"""
if hasattr(activity_tool,'SQLQueue_readMessageList'):
#return # Do nothing here to precent overlocking
path = '/'.join(object_path)
# Parse each message in registered
......@@ -178,6 +181,7 @@ class SQLQueue(RAMQueue):
def getMessageList(self, activity_tool, processing_node=None):
message_list = []
if hasattr(activity_tool,'SQLQueue_readMessageList'):
result = activity_tool.SQLQueue_readMessageList(path=None, method_id=None, processing_node=None)
for line in result:
m = self.loadMessage(line.message)
......@@ -188,6 +192,7 @@ class SQLQueue(RAMQueue):
def distribute(self, activity_tool, node_count):
processing_node = 1
if hasattr(activity_tool,'SQLQueue_readMessageList'):
result = activity_tool.SQLQueue_readMessageList(path=None, method_id=None, processing_node = -1) # Only assign non assigned messages
#LOG('distribute count',0,str(len(result)) )
#LOG('distribute count',0,str(map(lambda x:x.uid, result)))
......
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