def getPriority(self, activity_tool, processing_node, node_set=None): if node_set is None: q = ("SELECT 3*priority, date FROM %s" " WHERE processing_node=0 AND date <= UTC_TIMESTAMP(6)" " ORDER BY priority, date LIMIT 1" % self.sql_table) else: subquery = ( "(SELECT 3*priority{} as effective_priority, date FROM %s" " WHERE {} AND processing_node=0 AND date <= UTC_TIMESTAMP(6)" " ORDER BY priority, date LIMIT 1)" % self.sql_table).format node = 'node=%s' % processing_node # "ALL" on all but one, to incur deduplication cost only once. # "UNION ALL" between the two naturally distinct sets. q = ( "SELECT * FROM (%s UNION ALL %s UNION %s%s) as t" " ORDER BY effective_priority, date LIMIT 1" % ( subquery(-1, node), subquery('', 'node=0'), subquery('+IF(node, IF(%s, -1, 1), 0)' % node, 'node>=0'), ' UNION ALL ' + subquery(-1, 'node IN (%s)' % ','.join(map(str, node_set))) if node_set else '', )) result = activity_tool.getSQLConnection().query(q, 0)[1] if result: return result[0] return Queue.getPriority(self, activity_tool, processing_node, node_set)
def getPriority(self, activity_tool, node=None): if node is None: q = ("SELECT 3*priority, date FROM %s" " WHERE processing_node=0 AND date <= UTC_TIMESTAMP(6)" " ORDER BY priority, date LIMIT 1" % self.sql_table) else: subquery = ("(SELECT 3*priority{} as effective_priority, date FROM %s" " WHERE {} AND processing_node=0 AND date <= UTC_TIMESTAMP(6)" " ORDER BY priority, date LIMIT 1)" % self.sql_table).format node = 'node=%s' % node q = ("SELECT * FROM (%s UNION ALL %s UNION %s) as t" " ORDER BY effective_priority, date LIMIT 1" % ( subquery(-1, node), subquery('', 'node=0'), subquery('+IF(node, IF(%s, -1, 1), 0)' % node, 1), )) result = activity_tool.getSQLConnection().query(q, 0)[1] if result: return result[0] return Queue.getPriority(self, activity_tool, node)
def getPriority(self, activity_tool): result = activity_tool.SQLBase_getPriority(table=self.sql_table) if result: result, = result return result['priority'], result['date'] return Queue.getPriority(self, activity_tool)
def getPriority(self, activity_tool): result = activity_tool.SQLBase_getPriority(table=self.sql_table) if result: assert len(result) == 1, len(result) return result[0]['priority'] return Queue.getPriority(self, activity_tool)
def getPriority(self, activity_tool): result = activity_tool.getSQLConnection().query( "SELECT priority, date FROM %s" " WHERE processing_node=0 AND date <= UTC_TIMESTAMP(6)" " ORDER BY priority, date LIMIT 1" % self.sql_table, 0)[1] return result[0] if result else Queue.getPriority(self, activity_tool)