def insert(self, resource_id, hostname, filename, start, end, jobid):
"""
Insert a job record
"""
cur = self.con.cursor()
try:
if hostname not in self._hostnamecache:
cur.execute("INSERT IGNORE INTO hosts (hostname) VALUES (%s)", [hostname])
self.con.commit()
self._hostnamecache[hostname] = 1
query = """INSERT INTO archive (hostid, filename, start_time_ts, end_time_ts, jobid)
VALUES( (SELECT id FROM hosts WHERE hostname = %s),%s,%s,%s,%s)
ON DUPLICATE KEY UPDATE start_time_ts=%s, end_time_ts=%s"""
cur.execute(query, [hostname, filename, start, end, jobid, start, end])
except mdb.IntegrityError as e:
if e[0] != 1062:
raise e
# else:
# Todo - check that the blobs match on duplicate records
self.buffered += 1
if self.buffered > 100:
self.con.commit()
self.buffered = 0
评论列表
文章目录