def WriteClientStats(self, client_id: Text, stats: rdf_client_stats.ClientStats, cursor=None) -> None: """Stores a ClientStats instance.""" if stats.timestamp is None: stats.timestamp = rdfvalue.RDFDatetime.Now() try: cursor.execute( """ INSERT INTO client_stats (client_id, payload, timestamp) VALUES (%s, %s, FROM_UNIXTIME(%s)) ON DUPLICATE KEY UPDATE payload=VALUES(payload) """, [ db_utils.ClientIDToInt(client_id), stats.SerializeToBytes(), mysql_utils.RDFDatetimeToTimestamp(stats.timestamp) ]) except MySQLdb.IntegrityError as e: if e.args[0] == mysql_error_constants.NO_REFERENCED_ROW_2: raise db.UnknownClientError(client_id, cause=e) else: raise
def WriteClientStats(self, client_id: Text, stats: rdf_client_stats.ClientStats) -> None: """Stores a ClientStats instance.""" if client_id not in collection.Flatten(self.ReadAllClientIDs()): raise db.UnknownClientError(client_id) if stats.timestamp is None: stats.timestamp = rdfvalue.RDFDatetime.Now() copy = rdf_client_stats.ClientStats(stats) self.client_stats[client_id][copy.timestamp] = copy