grr/server/grr_response_server/databases/mysql_flows.py
def _LeaseMessageHandlerRequests(self, lease_time, limit, cursor=None):
    """Leases a number of message handler requests up to the indicated limit."""

    now = rdfvalue.RDFDatetime.Now()
    now_str = mysql_utils.RDFDatetimeToMysqlString(now)

    expiry = now + lease_time
    expiry_str = mysql_utils.RDFDatetimeToMysqlString(expiry)

    query = ("UPDATE message_handler_requests "
             "SET leased_until=%s, leased_by=%s "
             "WHERE leased_until IS NULL OR leased_until < %s "
             "LIMIT %s")

    id_str = utils.ProcessIdString()
    args = (expiry_str, id_str, now_str, limit)
    updated = cursor.execute(query, args)

    if updated == 0:
      return []

    cursor.execute(
        "SELECT timestamp, request FROM message_handler_requests "
        "WHERE leased_by=%s AND leased_until=%s LIMIT %s",
        (id_str, expiry_str, updated))
    res = []
    for timestamp, request in cursor.fetchall():
      req = rdf_objects.MessageHandlerRequest.FromSerializedString(request)
      req.timestamp = mysql_utils.MysqlToRDFDatetime(timestamp)
      req.leased_until = expiry
      req.leased_by = id_str
      res.append(req)

    return res
Leases a number of message handler requests up to the indicated limit.
Leases a number of message handler requests up to the indicated limit.
Leases a number of message handler requests up to the indicated limit .
def _LeaseMessageHandlerRequests(self, lease_time, limit, cursor=None):
    now = rdfvalue.RDFDatetime.Now()
    now_str = mysql_utils.RDFDatetimeToMysqlString(now)
    expiry = now + lease_time
    expiry_str = mysql_utils.RDFDatetimeToMysqlString(expiry)
    query = ("UPDATE message_handler_requests "
             "SET leased_until=%s, leased_by=%s "
             "WHERE leased_until IS NULL OR leased_until < %s "
             "LIMIT %s")
    id_str = utils.ProcessIdString()
    args = (expiry_str, id_str, now_str, limit)
    updated = cursor.execute(query, args)
    if updated == 0:
      return []
    cursor.execute(
        "SELECT timestamp, request FROM message_handler_requests "
        "WHERE leased_by=%s AND leased_until=%s LIMIT %s",
        (id_str, expiry_str, updated))
    res = []
    for timestamp, request in cursor.fetchall():
      req = rdf_objects.MessageHandlerRequest.FromSerializedString(request)
      req.timestamp = mysql_utils.MysqlToRDFDatetime(timestamp)
      req.leased_until = expiry
      req.leased_by = id_str
      res.append(req)
    return res
def _LeaseMessageHandlerRequests ( self , lease_time , limit , cursor = None ) : now = rdfvalue . RDFDatetime . Now ( ) now_str = mysql_utils . RDFDatetimeToMysqlString ( now ) expiry = now + lease_time expiry_str = mysql_utils . RDFDatetimeToMysqlString ( expiry ) query = ( "UPDATE message_handler_requests " "SET leased_until=%s, leased_by=%s " "WHERE leased_until IS NULL OR leased_until < %s " "LIMIT %s" ) id_str = utils . ProcessIdString ( ) args = ( expiry_str , id_str , now_str , limit ) updated = cursor . execute ( query , args ) if updated == 0 : return [ ] cursor . execute ( "SELECT timestamp, request FROM message_handler_requests " "WHERE leased_by=%s AND leased_until=%s LIMIT %s" , ( id_str , expiry_str , updated ) ) res = [ ] for timestamp , request in cursor . fetchall ( ) : req = rdf_objects . MessageHandlerRequest . FromSerializedString ( request ) req . timestamp = mysql_utils . MysqlToRDFDatetime ( timestamp ) req . leased_until = expiry req . leased_by = id_str res . append ( req ) return res
Leases a number of message handler requests up to the indicated limit.
Leases a number of message handler requests up to the indicated limit .
"""Leases a number of message handler requests up to the indicated limit."""
self
lease_time
limit
cursor