summaryrefslogtreecommitdiff
path: root/src/dbctx.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2023-06-29 02:17:11 -0700
committeriximeow <me@iximeow.net>2023-06-29 02:17:11 -0700
commit954a65107b59b9a547ca5ce0f1fa2dd41e013cd6 (patch)
treee4712344007c139b01f9f361bede9ef518c1fd1b /src/dbctx.rs
parent9f44782ebd991c9a4d3d1d33cb9e6b34ed221b88 (diff)
more gross hacks to get a list of active jobs
Diffstat (limited to 'src/dbctx.rs')
-rw-r--r--src/dbctx.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/dbctx.rs b/src/dbctx.rs
index a5de23d..a646c19 100644
--- a/src/dbctx.rs
+++ b/src/dbctx.rs
@@ -361,6 +361,20 @@ impl DbCtx {
Ok(artifacts)
}
+ pub fn repo_by_id(&self, id: u64) -> Result<Option<Repo>, String> {
+ self.conn.lock()
+ .unwrap()
+ .query_row("select * from repos where id=?1", [id], |row| {
+ let (id, repo_name) = row.try_into().unwrap();
+ Ok(Repo {
+ id,
+ name: repo_name,
+ })
+ })
+ .optional()
+ .map_err(|e| e.to_string())
+ }
+
pub fn get_repos(&self) -> Result<Vec<Repo>, String> {
let conn = self.conn.lock().unwrap();
@@ -444,6 +458,38 @@ impl DbCtx {
Ok(jobs)
}
+ pub fn get_started_jobs(&self) -> Result<Vec<Job>, String> {
+ let conn = self.conn.lock().unwrap();
+
+ let mut started_query = conn.prepare(sql::STARTED_JOBS).unwrap();
+ let mut jobs = started_query.query([]).unwrap();
+ let mut started = Vec::new();
+
+ while let Some(row) = jobs.next().unwrap() {
+ let (id, artifacts_path, state, run_host, remote_id, commit_id, created_time, start_time, complete_time, build_token, job_timeout, source, build_result, final_text) = row.try_into().unwrap();
+ let state: u8 = state;
+
+ started.push(Job {
+ id,
+ artifacts_path,
+ state: state.try_into().unwrap(),
+ run_host,
+ remote_id,
+ commit_id,
+ created_time,
+ start_time,
+ complete_time,
+ build_token,
+ job_timeout,
+ source,
+ build_result,
+ final_text,
+ });
+ }
+
+ Ok(started)
+ }
+
pub fn get_pending_jobs(&self) -> Result<Vec<PendingJob>, String> {
let conn = self.conn.lock().unwrap();