return job
- ## Logging stuff
-
- def log(self, action, user=None, state=None, builder=None, test_job=None):
- user_id = None
- if user:
- user_id = user.id
-
- builder_id = None
- if builder:
- builder_id = builder.id
-
- test_job_id = None
- if test_job:
- test_job_id = test_job.id
-
- self.db.execute("INSERT INTO jobs_history(job_id, action, state, user_id, \
- time, builder_id, test_job_id) VALUES(%s, %s, %s, %s, NOW(), %s, %s)",
- self.id, action, state, user_id, builder_id, test_job_id)
-
- def get_log(self, limit=None, offset=None, user=None):
- query = "SELECT * FROM jobs_history"
-
- conditions = ["job_id = %s",]
- args = [self.id,]
-
- if user:
- conditions.append("user_id = %s")
- args.append(user.id)
-
- if conditions:
- query += " WHERE %s" % " AND ".join(conditions)
-
- query += " ORDER BY time DESC"
-
- if limit:
- if offset:
- query += " LIMIT %s,%s"
- args += [offset, limit,]
- else:
- query += " LIMIT %s"
- args += [limit,]
-
- entries = []
- for entry in self.db.query(query, *args):
- entry = logs.JobLogEntry(self.backend, entry)
- entries.append(entry)
-
- return entries
-
# Builder
@lazy_property