grr/server/grr_response_server/databases/mysql_flows.py
def _LeaseFlowProcessingReqests(self, cursor=None):
    """Leases a number of flow processing requests."""
    now = rdfvalue.RDFDatetime.Now()
    now_str = mysql_utils.RDFDatetimeToMysqlString(now)

    expiry = now + rdfvalue.Duration("10m")
    expiry_str = mysql_utils.RDFDatetimeToMysqlString(expiry)

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

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

    if updated == 0:
      return []

    cursor.execute(
        "SELECT timestamp, request FROM flow_processing_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_flows.FlowProcessingRequest.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 flow processing requests.
Leases a number of flow processing requests.
Leases a number of flow processing requests .
def _LeaseFlowProcessingReqests(self, cursor=None):
    now = rdfvalue.RDFDatetime.Now()
    now_str = mysql_utils.RDFDatetimeToMysqlString(now)
    expiry = now + rdfvalue.Duration("10m")
    expiry_str = mysql_utils.RDFDatetimeToMysqlString(expiry)
    query = ("UPDATE flow_processing_requests "
             "SET leased_until=%s, leased_by=%s "
             "WHERE (delivery_time IS NULL OR delivery_time <= %s) AND "
             "(leased_until IS NULL OR leased_until < %s) "
             "LIMIT %s")
    id_str = utils.ProcessIdString()
    args = (expiry_str, id_str, now_str, now_str, 50)
    updated = cursor.execute(query, args)
    if updated == 0:
      return []
    cursor.execute(
        "SELECT timestamp, request FROM flow_processing_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_flows.FlowProcessingRequest.FromSerializedString(request)
      req.timestamp = mysql_utils.MysqlToRDFDatetime(timestamp)
      req.leased_until = expiry
      req.leased_by = id_str
      res.append(req)
    return res
def _LeaseFlowProcessingReqests ( self , cursor = None ) : now = rdfvalue . RDFDatetime . Now ( ) now_str = mysql_utils . RDFDatetimeToMysqlString ( now ) expiry = now + rdfvalue . Duration ( "10m" ) expiry_str = mysql_utils . RDFDatetimeToMysqlString ( expiry ) query = ( "UPDATE flow_processing_requests " "SET leased_until=%s, leased_by=%s " "WHERE (delivery_time IS NULL OR delivery_time <= %s) AND " "(leased_until IS NULL OR leased_until < %s) " "LIMIT %s" ) id_str = utils . ProcessIdString ( ) args = ( expiry_str , id_str , now_str , now_str , 50 ) updated = cursor . execute ( query , args ) if updated == 0 : return [ ] cursor . execute ( "SELECT timestamp, request FROM flow_processing_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_flows . FlowProcessingRequest . 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 flow processing requests.
Leases a number of flow processing requests .
"""Leases a number of flow processing requests."""
self
cursor