Commit e2ff442c authored by Sebastien Robin's avatar Sebastien Robin

Commit work done by Vincent

  Make ActivityTool:Message.getObjectList simple to use: detect internaly 
wether an expand method must be called, catch exception when object on which 
the activity was executed cannot be found.
  Remove broadcast message support.
  Merge indexes on processing_node and processing columns on both message and 
message_queue tables.
  Always use SQL server's time.
  Do not update processing node value when setting the message as being 
processed.
  Commit SQL connection as soon as messages get assigned to reduce lock 
duration.
  Make SQLDict ZSQLMethods support list of uids instead of single value per 
call.
  Make ZSQLMethod handle processing_node differently if it's 0 or None (when 
not passed as parameter, behave as if it's None).
  Do not force all parameters to be passed to SQLQueue_setPriority.
  Factorise SQL code inside <dtml-if> blocks.
  Allow to select ranges of lines in readMessageList with a custom offset.
  When reseting message processing state at first activity execution pass 
after a node start, also reset the processing_node.
  Commit SQL connection as soon as messages are set to processing state, 
mainly to make it visible outside current connection.
  Add a common class for SQL-using activity queues.
  CMFActivity/Activity/SQLDict.py
    Remove unused (and broken) prepareQueueMessage method.
    Replace a tab by spaces.
    Add ZSQLMethod wrappers for new ZSQLMethods.
    Split dequeueMessage into dequeueMessage, getProcessableMessageList, 
finalizeMessage_Execution.
    Return True instead of 0 in case of an important error, in order to 
prevent CMFActivity from doing infinite loops  over dequeueMessage when 
something goes wrong.
  CMFActivity/Activity/Queue.py
    Allow caller to specify the current date and transmit it when recursing. 
Fallback on DateTime (calculate just once) if not specified.
  CMFActivity/Activity/SQLQueue.py
    Precompute parameters in prepareQueueMessage to make it easier to add a 
log when needed. Also reduces the distance with SQLDict's equivalent method.
    Add ZSQLMethod wrappers for new ZSQLMethods.
    Split dequeueMessage into dequeueMessage, getProcessableMessageList, 
finalizeMessage_Execution.
    Return True instead of 0 in case of an important error, in order to 
prevent CMFActivity from doing infinite loops  over dequeueMessage when 
something goes wrong.
  Add scripts to monitor activity distribution.  
  Remove unused ZSQLMethods.
  Add new ZSQLMethods related to the new distribution scheme and SQL server 
time grabbing.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17759 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 90018457
...@@ -117,7 +117,6 @@ class Queue: ...@@ -117,7 +117,6 @@ class Queue:
self.is_alive = {} self.is_alive = {}
self.is_awake = {} self.is_awake = {}
self.is_initialized = 0 self.is_initialized = 0
self.max_processing_date = DateTime()
def initialize(self, activity_tool): def initialize(self, activity_tool):
# This is the only moment when # This is the only moment when
...@@ -206,7 +205,7 @@ class Queue: ...@@ -206,7 +205,7 @@ class Queue:
return message_list return message_list
def getExecutableMessageList(self, activity_tool, message, message_dict, def getExecutableMessageList(self, activity_tool, message, message_dict,
validation_text_dict): validation_text_dict, now_date=None):
"""Get messages which have no dependent message, and store them in the dictionary. """Get messages which have no dependent message, and store them in the dictionary.
If the passed message itself is executable, simply store only that message. If the passed message itself is executable, simply store only that message.
...@@ -233,6 +232,7 @@ class Queue: ...@@ -233,6 +232,7 @@ class Queue:
if message_list: if message_list:
# The result is not empty, so this message is not executable. # The result is not empty, so this message is not executable.
validation_text_dict[message.order_validation_text] = 0 validation_text_dict[message.order_validation_text] = 0
if now_date is None:
now_date = DateTime() now_date = DateTime()
for activity, m in message_list: for activity, m in message_list:
# Note that the messages may contain ones which are already assigned or not # Note that the messages may contain ones which are already assigned or not
...@@ -242,7 +242,7 @@ class Queue: ...@@ -242,7 +242,7 @@ class Queue:
message_dict[message.uid] = None message_dict[message.uid] = None
try: try:
self.getExecutableMessageList(activity_tool, m, message_dict, self.getExecutableMessageList(activity_tool, m, message_dict,
validation_text_dict) validation_text_dict, now_date=now_date)
finally: finally:
del message_dict[message.uid] del message_dict[message.uid]
else: else:
......
##############################################################################
#
# Copyright (c) 2007 Nexedi SA and Contributors. All Rights Reserved.
# Vincent Pelletier <vincent@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
class SQLBase:
"""
Define a set of common methods for SQL-based storage of activities.
"""
def getNow(self, context):
"""
Return the current value for SQL server's NOW().
Note that this value is not cached, and is not transactionnal on MySQL
side.
"""
result = context.SQLBase_getNow()
assert len(result) == 1
assert len(result[0]) == 1
return result[0][0]
This diff is collapsed.
This diff is collapsed.
...@@ -130,14 +130,16 @@ class Message: ...@@ -130,14 +130,16 @@ class Message:
def getObjectList(self, activity_tool): def getObjectList(self, activity_tool):
"""return the list of object that can be expanded from this message.""" """return the list of object that can be expanded from this message."""
object_list = []
try: try:
object_list.append(self.getObject(activity_tool))
except KeyError:
pass
else:
if self.hasExpandMethod():
expand_method_id = self.activity_kw['expand_method_id'] expand_method_id = self.activity_kw['expand_method_id']
obj = self.getObject(activity_tool)
# FIXME: how to pass parameters? # FIXME: how to pass parameters?
object_list = getattr(obj, expand_method_id)() object_list = getattr(object_list[0], expand_method_id)()
except KeyError:
object_list = [self.getObject(activity_tool)]
return object_list return object_list
def hasExpandMethod(self): def hasExpandMethod(self):
......
<dtml-comment>
title:
connection_id:cmf_activity_sql_connection
max_rows:0
max_cache:0
cache_time:0
class_name:
class_file:
</dtml-comment>
<params></params>
SELECT NOW()
...@@ -11,7 +11,7 @@ class_file: ...@@ -11,7 +11,7 @@ class_file:
processing_node processing_node
method_id method_id
uid uid
broadcast</params> </params>
UPDATE message UPDATE message
SET SET
processing_node=<dtml-sqlvar processing_node type="int">, processing_node=<dtml-sqlvar processing_node type="int">,
...@@ -26,6 +26,5 @@ WHERE ...@@ -26,6 +26,5 @@ WHERE
AND path = <dtml-sqlvar path type="string"> AND path = <dtml-sqlvar path type="string">
<dtml-if method_id>AND method_id = <dtml-sqlvar method_id type="string"></dtml-if> <dtml-if method_id>AND method_id = <dtml-sqlvar method_id type="string"></dtml-if>
</dtml-if> </dtml-if>
<dtml-if broadcast> <dtml-var sql_delimiter>
AND broadcast = <dtml-sqlvar broadcast type="int"> COMMIT
</dtml-if>
...@@ -11,7 +11,7 @@ class_file: ...@@ -11,7 +11,7 @@ class_file:
UPDATE UPDATE
message message
SET SET
processing="0" processing=0,
processing_node=0
WHERE WHERE
processing="1" processing_node=<dtml-sqlvar processing_node type="int">
AND processing_node="<dtml-sqlvar processing_node type="int">"
...@@ -17,7 +17,6 @@ CREATE TABLE `message` ( ...@@ -17,7 +17,6 @@ CREATE TABLE `message` (
`processing` TINYINT NOT NULL DEFAULT 0, `processing` TINYINT NOT NULL DEFAULT 0,
`processing_date` DATETIME, `processing_date` DATETIME,
`priority` TINYINT NOT NULL DEFAULT 0, `priority` TINYINT NOT NULL DEFAULT 0,
`broadcast` TINYINT NOT NULL DEFAULT 0,
`group_method_id` VARCHAR(255) NOT NULL DEFAULT '', `group_method_id` VARCHAR(255) NOT NULL DEFAULT '',
`tag` VARCHAR(255) NOT NULL, `tag` VARCHAR(255) NOT NULL,
`retry` TINYINT UNSIGNED NOT NULL DEFAULT 0, `retry` TINYINT UNSIGNED NOT NULL DEFAULT 0,
...@@ -26,8 +25,7 @@ CREATE TABLE `message` ( ...@@ -26,8 +25,7 @@ CREATE TABLE `message` (
PRIMARY KEY (`uid`), PRIMARY KEY (`uid`),
KEY (`path`), KEY (`path`),
KEY (`method_id`), KEY (`method_id`),
KEY (`processing_node`), KEY `processing_node_processing` (`processing_node`, `processing`),
KEY (`processing`),
KEY (`priority`), KEY (`priority`),
KEY (`tag`), KEY (`tag`),
KEY (`order_validation_text`) KEY (`order_validation_text`)
......
<dtml-comment>
title:
connection_id:cmf_activity_sql_connection
max_rows:0
max_cache:0
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>
processing_node
uid
to_date
path
method_id
group_method_id
order_validation_text
tag
</params>
DELETE FROM
message
WHERE
processing_node IN (0, <dtml-sqlvar processing_node type="int">)
AND uid != <dtml-sqlvar uid type="int">
AND date <= <dtml-sqlvar to_date type="datetime">
AND path = <dtml-sqlvar path type="string">
AND method_id = <dtml-sqlvar method_id type="string">
AND group_method_id = <dtml-sqlvar group_method_id type="string">
AND order_validation_text = <dtml-sqlvar order_validation_text type="string">
AND tag IN ('', <dtml-sqlvar tag type="string">)
<dtml-var sql_delimiter>
COMMIT
<dtml-comment>
title:
connection_id:cmf_activity_sql_connection
max_rows:0
max_cache:0
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>uid_list</params>
UPDATE
message
SET
processing_node=0,
processing=0
WHERE
uid IN (
<dtml-in prefix="uid" expr="uid_list"><dtml-sqlvar uid_item type="int"><dtml-if sequence-end><dtml-else>, </dtml-if></dtml-in>
)
<dtml-var sql_delimiter>
COMMIT
...@@ -7,14 +7,14 @@ cache_time:0 ...@@ -7,14 +7,14 @@ cache_time:0
class_name: class_name:
class_file: class_file:
</dtml-comment> </dtml-comment>
<params>uid <params>uid</params>
processing_node</params>
UPDATE message UPDATE message
SET SET
processing_date = <dtml-sqlvar "_.DateTime()" type="datetime">, processing_date = NOW(),
processing = 1, processing = 1
processing_node = <dtml-sqlvar processing_node type="int">
WHERE WHERE
uid IN ( uid IN (
<dtml-in uid><dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in> <dtml-in uid><dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>
) )
<dtml-var sql_delimiter>
COMMIT
<dtml-comment>
title:
connection_id:cmf_activity_sql_connection
max_rows:0
max_cache:0
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>processing_node
priority
to_date
to_processing_date
group_method_id
order_validation_text</params>
SELECT * FROM
message
WHERE
processing = 0
<dtml-if processing_node> AND processing_node = <dtml-sqlvar processing_node type="int"> </dtml-if>
<dtml-if priority> AND priority = <dtml-sqlvar priority type="int"> </dtml-if>
<dtml-if to_date>AND date <= <dtml-sqlvar to_date type="datetime"> </dtml-if>
<dtml-if group_method_id>AND group_method_id = <dtml-sqlvar group_method_id type="string"> </dtml-if>
<dtml-if order_validation_text>AND order_validation_text = <dtml-sqlvar order_validation_text type="string"> </dtml-if>
ORDER BY
priority, date, uid
<dtml-if group_method_id>
LIMIT 100
<dtml-else>
LIMIT 1
</dtml-if>
<dtml-comment> <dtml-comment>
title: title:
connection_id:cmf_activity_sql_connection connection_id:cmf_activity_sql_connection
max_rows:1000 max_rows:0
max_cache:0 max_cache:0
cache_time:0 cache_time:0
class_name: class_name:
...@@ -12,7 +12,10 @@ method_id ...@@ -12,7 +12,10 @@ method_id
processing_node processing_node
priority priority
include_processing include_processing
to_date</params> to_date
offset:int=0
count:int=1000
</params>
SELECT * FROM SELECT * FROM
message message
WHERE WHERE
...@@ -20,10 +23,11 @@ WHERE ...@@ -20,10 +23,11 @@ WHERE
<dtml-if expr="not(include_processing)"> <dtml-if expr="not(include_processing)">
AND processing = 0 AND processing = 0
</dtml-if> </dtml-if>
<dtml-if processing_node> AND processing_node = <dtml-sqlvar processing_node type="int"> </dtml-if> <dtml-if expr="processing_node is not None"> AND processing_node = <dtml-sqlvar processing_node type="int"> </dtml-if>
<dtml-if priority> AND priority = <dtml-sqlvar priority type="int"> </dtml-if> <dtml-if priority> AND priority = <dtml-sqlvar priority type="int"> </dtml-if>
<dtml-if path>AND path = <dtml-sqlvar path type="string"> </dtml-if> <dtml-if path>AND path = <dtml-sqlvar path type="string"> </dtml-if>
<dtml-if method_id> AND method_id = <dtml-sqlvar method_id type="string"> </dtml-if> <dtml-if method_id> AND method_id = <dtml-sqlvar method_id type="string"> </dtml-if>
<dtml-if to_date> AND date <= <dtml-sqlvar to_date type="datetime"> </dtml-if> <dtml-if to_date> AND date <= <dtml-sqlvar to_date type="datetime"> </dtml-if>
ORDER BY ORDER BY
priority, date, uid priority, date, uid
LIMIT <dtml-sqlvar offset type="int">, <dtml-sqlvar count type="int">
...@@ -17,7 +17,7 @@ SELECT uid FROM ...@@ -17,7 +17,7 @@ SELECT uid FROM
message message
WHERE WHERE
processing = 0 processing = 0
<dtml-if processing_node> AND processing_node = <dtml-sqlvar processing_node type="int"> </dtml-if> <dtml-if expr="processing_node is not None"> AND processing_node = <dtml-sqlvar processing_node type="int"> </dtml-if>
<dtml-if method_id> AND method_id = <dtml-sqlvar method_id type="string"> </dtml-if> <dtml-if method_id> AND method_id = <dtml-sqlvar method_id type="string"> </dtml-if>
<dtml-if path> AND path = <dtml-sqlvar path type="string"> </dtml-if> <dtml-if path> AND path = <dtml-sqlvar path type="string"> </dtml-if>
<dtml-if to_date> AND date <= <dtml-sqlvar to_date type="datetime"> </dtml-if> <dtml-if to_date> AND date <= <dtml-sqlvar to_date type="datetime"> </dtml-if>
......
<dtml-comment>
title:
connection_id:cmf_activity_sql_connection
max_rows:0
max_cache:0
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>processing_node
to_date
limit
group_method_id
order_validation_text</params>
UPDATE
message
SET
processing_node=<dtml-sqlvar processing_node type="int">
WHERE
processing_node=0
AND date <= <dtml-sqlvar to_date type="datetime">
<dtml-if group_method_id> AND group_method_id = <dtml-sqlvar group_method_id type="string"> </dtml-if>
<dtml-if order_validation_text> AND order_validation_text = <dtml-sqlvar order_validation_text type="string"> </dtml-if>
ORDER BY
priority, date, uid
<dtml-if limit>
LIMIT <dtml-sqlvar limit type="int">
</dtml-if>
<dtml-var sql_delimiter>
COMMIT
<dtml-comment>
title:
connection_id:cmf_activity_sql_connection
max_rows:0
max_cache:0
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>processing_node
limit</params>
SELECT
*
FROM
message
WHERE
processing_node = <dtml-sqlvar processing_node type="int">
AND processing = 0
<dtml-if limit>
LIMIT <dtml-sqlvar limit type="int">
</dtml-if>
...@@ -36,7 +36,7 @@ WHERE ...@@ -36,7 +36,7 @@ WHERE
<dtml-in uid><dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in> <dtml-in uid><dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>
) )
</dtml-if> </dtml-if>
<dtml-if processing_node> <dtml-if expr="_.getattr(_, 'processing_node', None) is not None">
AND processing_node = <dtml-sqlvar processing_node type="int"> AND processing_node = <dtml-sqlvar processing_node type="int">
</dtml-if> </dtml-if>
<dtml-if order_validation_text> <dtml-if order_validation_text>
......
...@@ -20,6 +20,6 @@ SET ...@@ -20,6 +20,6 @@ SET
</dtml-if> </dtml-if>
WHERE WHERE
1 = 1 1 = 1
<dtml-if processing_node> <dtml-if expr="processing_node is not None">
AND processing_node = <dtml-sqlvar processing_node type="int"> AND processing_node = <dtml-sqlvar processing_node type="int">
</dtml-if> </dtml-if>
...@@ -12,7 +12,6 @@ path ...@@ -12,7 +12,6 @@ path
method_id method_id
message message
priority priority
broadcast
date date
processing_node=-1 processing_node=-1
group_method_id group_method_id
...@@ -22,12 +21,11 @@ INSERT INTO message ...@@ -22,12 +21,11 @@ INSERT INTO message
SET SET
uid = <dtml-sqlvar uid type="int">, uid = <dtml-sqlvar uid type="int">,
path = <dtml-sqlvar path type="string">, path = <dtml-sqlvar path type="string">,
<dtml-if date>date = <dtml-sqlvar date type="datetime">, <dtml-else>date = <dtml-sqlvar "_.DateTime()" type="datetime">, </dtml-if> date = <dtml-if date><dtml-sqlvar date type="datetime"><dtml-else>NOW()</dtml-if>,
method_id = <dtml-sqlvar method_id type="string">, method_id = <dtml-sqlvar method_id type="string">,
processing_node = <dtml-sqlvar processing_node type="int">, processing_node = <dtml-sqlvar processing_node type="int">,
processing = 0, processing = 0,
priority = <dtml-sqlvar priority type="int">, priority = <dtml-sqlvar priority type="int">,
broadcast = <dtml-sqlvar broadcast type="int">,
group_method_id = <dtml-sqlvar group_method_id type="string">, group_method_id = <dtml-sqlvar group_method_id type="string">,
tag = <dtml-sqlvar tag type="string">, tag = <dtml-sqlvar tag type="string">,
order_validation_text = <dtml-sqlvar order_validation_text type="string">, order_validation_text = <dtml-sqlvar order_validation_text type="string">,
......
...@@ -12,26 +12,24 @@ path_list ...@@ -12,26 +12,24 @@ path_list
method_id_list method_id_list
message_list message_list
priority_list priority_list
broadcast_list
date_list date_list
processing_node_list processing_node_list
group_method_id_list group_method_id_list
tag_list tag_list
order_validation_text_list</params> order_validation_text_list</params>
INSERT INTO message INSERT INTO message
(uid, path, date, method_id, processing_node, processing, priority, broadcast, group_method_id, tag, order_validation_text, message) (uid, path, date, method_id, processing_node, processing, priority, group_method_id, tag, order_validation_text, message)
VALUES VALUES
<dtml-in prefix="loop" expr="_.range(_.len(path_list))"> <dtml-in prefix="loop" expr="_.range(_.len(path_list))">
<dtml-if sequence-start><dtml-else>,</dtml-if> <dtml-if sequence-start><dtml-else>,</dtml-if>
( (
<dtml-sqlvar expr="uid_list[loop_item]" type="int">, <dtml-sqlvar expr="uid_list[loop_item]" type="int">,
<dtml-sqlvar expr="path_list[loop_item]" type="string">, <dtml-sqlvar expr="path_list[loop_item]" type="string">,
<dtml-if date_list><dtml-sqlvar expr="date_list[loop_item]" type="datetime"><dtml-else><dtml-sqlvar "_.DateTime()" type="datetime"></dtml-if>, <dtml-if date_list><dtml-if expr="date_list[loop_item] is not None"><dtml-sqlvar expr="date_list[loop_item]" type="datetime"><dtml-else>NOW()</dtml-if><dtml-else>NOW()</dtml-if>,
<dtml-sqlvar expr="method_id_list[loop_item]" type="string">, <dtml-sqlvar expr="method_id_list[loop_item]" type="string">,
<dtml-if processing_node_list><dtml-sqlvar expr="processing_node_list[loop_item]" type="int"><dtml-else>-1</dtml-if>, <dtml-if processing_node_list><dtml-sqlvar expr="processing_node_list[loop_item]" type="int"><dtml-else>-1</dtml-if>,
0, 0,
<dtml-sqlvar expr="priority_list[loop_item]" type="int">, <dtml-sqlvar expr="priority_list[loop_item]" type="int">,
<dtml-sqlvar expr="broadcast_list[loop_item]" type="int">,
<dtml-sqlvar expr="group_method_id_list[loop_item]" type="string">, <dtml-sqlvar expr="group_method_id_list[loop_item]" type="string">,
<dtml-sqlvar expr="tag_list[loop_item]" type="string">, <dtml-sqlvar expr="tag_list[loop_item]" type="string">,
<dtml-sqlvar expr="order_validation_text_list[loop_item]" type="string">, <dtml-sqlvar expr="order_validation_text_list[loop_item]" type="string">,
......
...@@ -10,7 +10,6 @@ class_file: ...@@ -10,7 +10,6 @@ class_file:
<params>path <params>path
processing_node processing_node
method_id method_id
broadcast
uid</params> uid</params>
UPDATE message_queue UPDATE message_queue
SET SET
...@@ -18,9 +17,11 @@ SET ...@@ -18,9 +17,11 @@ SET
processing=0 processing=0
WHERE WHERE
<dtml-if path> path = <dtml-sqlvar path type="string"> <dtml-if path> path = <dtml-sqlvar path type="string">
<dtml-else> uid = <dtml-sqlvar uid type="int"> </dtml-if> <dtml-else>
<dtml-if method_id> AND method_id = <dtml-sqlvar method_id type="string"></dtml-if> uid IN (
<dtml-if broadcast> <dtml-in uid><dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>
AND broadcast = <dtml-sqlvar broadcast type="int"> )
</dtml-if> </dtml-if>
<dtml-if method_id> AND method_id = <dtml-sqlvar method_id type="string"></dtml-if>
<dtml-var sql_delimiter>
COMMIT
...@@ -11,7 +11,7 @@ class_file: ...@@ -11,7 +11,7 @@ class_file:
UPDATE UPDATE
message_queue message_queue
SET SET
processing="0" processing=0,
processing_node=0
WHERE WHERE
processing="1" processing_node=<dtml-sqlvar processing_node type="int">
AND processing_node="<dtml-sqlvar processing_node type="int">"
...@@ -17,15 +17,13 @@ CREATE TABLE `message_queue` ( ...@@ -17,15 +17,13 @@ CREATE TABLE `message_queue` (
`processing` INT DEFAULT 0, `processing` INT DEFAULT 0,
`processing_date` datetime, `processing_date` datetime,
`priority` INT DEFAULT 0, `priority` INT DEFAULT 0,
`broadcast` INT DEFAULT 0,
`tag` VARCHAR(255), `tag` VARCHAR(255),
`message` LONGBLOB, `message` LONGBLOB,
PRIMARY KEY (`uid`), PRIMARY KEY (`uid`),
KEY `date` (`date`), KEY `date` (`date`),
KEY `path` (`path`), KEY `path` (`path`),
KEY `method_id` (`method_id`), KEY `method_id` (`method_id`),
KEY `processing_node` (`processing_node`), KEY `processing_node_processing` (`processing_node`, `processing`),
KEY `processing` (`processing`),
KEY `processing_date` (`processing_date`), KEY `processing_date` (`processing_date`),
KEY `priority` (`priority`), KEY `priority` (`priority`),
KEY `tag` (`tag`) KEY `tag` (`tag`)
......
<dtml-comment>
title:
connection_id:cmf_activity_sql_connection
max_rows:0
max_cache:0
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>uid_list</params>
UPDATE
message_queue
SET
processing_node=0,
processing=0
WHERE
uid IN (
<dtml-in prefix="uid" expr="uid_list"><dtml-sqlvar uid_item type="int"><dtml-if sequence-end><dtml-else>, </dtml-if></dtml-in>
)
<dtml-var sql_delimiter>
COMMIT
...@@ -11,7 +11,11 @@ class_file: ...@@ -11,7 +11,11 @@ class_file:
UPDATE UPDATE
message_queue message_queue
SET SET
processing_date = <dtml-sqlvar "_.DateTime()" type="datetime">, processing_date = NOW(),
processing=1 processing=1
WHERE WHERE
uid = <dtml-sqlvar uid type="int"> uid IN (
<dtml-in uid><dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>
)
<dtml-var sql_delimiter>
COMMIT
<dtml-comment>
title:
connection_id:cmf_activity_sql_connection
max_rows:1
max_cache:0
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>processing_node
priority
to_date</params>
SELECT * FROM
message_queue
WHERE
processing = 0
<dtml-if processing_node> AND processing_node = <dtml-sqlvar processing_node type="int"></dtml-if>
<dtml-if priority> AND priority = <dtml-sqlvar priority type="int"> </dtml-if>
<dtml-if to_date> AND date <= <dtml-sqlvar to_date type="datetime"> </dtml-if>
ORDER BY
priority, date, uid
<dtml-comment> <dtml-comment>
title: title:
connection_id:cmf_activity_sql_connection connection_id:cmf_activity_sql_connection
max_rows:1000 max_rows:0
max_cache:0 max_cache:0
cache_time:0 cache_time:0
class_name: class_name:
...@@ -11,15 +11,19 @@ class_file: ...@@ -11,15 +11,19 @@ class_file:
method_id method_id
processing_node processing_node
priority priority
to_date</params> to_date
offset:int=0
count:int=1000
</params>
SELECT * FROM SELECT * FROM
message_queue message_queue
WHERE WHERE
processing = 0 processing = 0
<dtml-if processing_node>AND processing_node = <dtml-sqlvar processing_node type="int"> </dtml-if> <dtml-if expr="processing_node is not None"> AND processing_node = <dtml-sqlvar processing_node type="int"> </dtml-if>
<dtml-if priority>AND priority = <dtml-sqlvar priority type="int"> </dtml-if> <dtml-if priority>AND priority = <dtml-sqlvar priority type="int"> </dtml-if>
<dtml-if path>AND path = <dtml-sqlvar path type="string"></dtml-if> <dtml-if path>AND path = <dtml-sqlvar path type="string"></dtml-if>
<dtml-if method_id>AND method_id = <dtml-sqlvar method_id type="string"></dtml-if> <dtml-if method_id>AND method_id = <dtml-sqlvar method_id type="string"></dtml-if>
<dtml-if to_date> AND date <= <dtml-sqlvar to_date type="datetime"> </dtml-if> <dtml-if to_date> AND date <= <dtml-sqlvar to_date type="datetime"> </dtml-if>
ORDER BY ORDER BY
priority, date, uid priority, date, uid
LIMIT <dtml-sqlvar offset type="int">, <dtml-sqlvar count type="int">
...@@ -15,6 +15,6 @@ SELECT uid FROM ...@@ -15,6 +15,6 @@ SELECT uid FROM
message_queue message_queue
WHERE WHERE
processing = 0 processing = 0
<dtml-if processing_node> AND processing_node = <dtml-sqlvar processing_node type="int"></dtml-if> <dtml-if expr="processing_node is not None"> AND processing_node = <dtml-sqlvar processing_node type="int"></dtml-if>
<dtml-if path> AND path = <dtml-sqlvar path type="string"></dtml-if> <dtml-if path> AND path = <dtml-sqlvar path type="string"></dtml-if>
<dtml-if to_date> AND date <= <dtml-sqlvar to_date type="datetime"> </dtml-if> <dtml-if to_date> AND date <= <dtml-sqlvar to_date type="datetime"> </dtml-if>
<dtml-comment>
title:
connection_id:cmf_activity_sql_connection
max_rows:0
max_cache:0
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>processing_node
to_date
limit
</params>
UPDATE
message_queue
SET
processing_node=<dtml-sqlvar processing_node type="int">
WHERE
processing_node=0
AND date <= <dtml-sqlvar to_date type="datetime">
ORDER BY
priority, date, uid
<dtml-if limit>
LIMIT <dtml-sqlvar limit type="int">
</dtml-if>
<dtml-var sql_delimiter>
COMMIT
<dtml-comment>
title:
connection_id:cmf_activity_sql_connection
max_rows:0
max_cache:0
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>processing_node
limit</params>
SELECT
*
FROM
message_queue
WHERE
processing_node = <dtml-sqlvar processing_node type="int">
AND processing = 0
<dtml-if limit>
LIMIT <dtml-sqlvar limit type="int">
</dtml-if>
...@@ -9,12 +9,21 @@ class_file: ...@@ -9,12 +9,21 @@ class_file:
</dtml-comment> </dtml-comment>
<params>uid <params>uid
priority priority
delay
date</params> date</params>
UPDATE UPDATE
message_queue message_queue
SET SET
priority = <dtml-sqlvar priority type="int">, processing = 0
processing = 0, <dtml-if priority>
date = <dtml-sqlvar date type="datetime"> , priority = <dtml-sqlvar priority type="int">
</dtml-if>
<dtml-if delay>
, date = DATE_ADD(NOW(), INTERVAL <dtml-sqlvar delay type="int"> SECOND)
<dtml-elif date>
, date = <dtml-sqlvar date type="datetime">
</dtml-if>
WHERE WHERE
uid = <dtml-sqlvar uid type="int"> uid IN (
<dtml-in uid><dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>
)
...@@ -16,6 +16,6 @@ SET ...@@ -16,6 +16,6 @@ SET
processing_date = processing_date - <dtml-sqlvar delay type="int"> processing_date = processing_date - <dtml-sqlvar delay type="int">
WHERE WHERE
1 = 1 1 = 1
<dtml-if processing_node> <dtml-if expr="processing_node is not None">
AND processing_node = <dtml-sqlvar processing_node type="int"> AND processing_node = <dtml-sqlvar processing_node type="int">
</dtml-if> </dtml-if>
...@@ -12,7 +12,6 @@ path ...@@ -12,7 +12,6 @@ path
method_id method_id
message message
priority priority
broadcast
processing_node processing_node
date date
tag</params> tag</params>
...@@ -20,12 +19,11 @@ INSERT INTO message_queue ...@@ -20,12 +19,11 @@ INSERT INTO message_queue
SET SET
uid = <dtml-sqlvar uid type="int">, uid = <dtml-sqlvar uid type="int">,
path = <dtml-sqlvar path type="string">, path = <dtml-sqlvar path type="string">,
<dtml-if date>date = <dtml-sqlvar date type="datetime">, <dtml-else>date = <dtml-sqlvar "_.DateTime()" type="datetime">, </dtml-if> date = <dtml-if date><dtml-sqlvar date type="datetime"><dtml-else>NOW()</dtml-if>,
method_id = <dtml-sqlvar method_id type="string">, method_id = <dtml-sqlvar method_id type="string">,
<dtml-if processing_node> <dtml-if processing_node>
processing_node = <dtml-sqlvar processing_node type="int">, processing_node = <dtml-sqlvar processing_node type="int">,
</dtml-if> </dtml-if>
broadcast = <dtml-sqlvar broadcast type="int">,
processing = 0, processing = 0,
priority = <dtml-sqlvar priority type="int">, priority = <dtml-sqlvar priority type="int">,
tag = <dtml-sqlvar tag type="string">, tag = <dtml-sqlvar tag type="string">,
......
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