From 6935d9f34f6475e6f294fce0bb6fd684440e4696 Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 4 Jul 2023 10:28:05 -0700 Subject: actually run spawned task to get clients jobs --- src/ci_driver.rs | 25 +++++++++---------------- src/dbctx.rs | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/ci_driver.rs b/src/ci_driver.rs index 3d6e351..5855352 100644 --- a/src/ci_driver.rs +++ b/src/ci_driver.rs @@ -60,30 +60,21 @@ fn reserve_artifacts_dir(run: u64) -> std::io::Result { async fn activate_run(dbctx: Arc, candidate: RunnerClient, job: &Job, run: &PendingRun) -> Result<(), String> { eprintln!("activating task {:?}", run); - let connection = dbctx.conn.lock().unwrap(); - - let (repo_id, remote_git_url): (u64, String) = connection - .query_row("select repo_id, remote_git_url from remotes where id=?1", [job.remote_id], |row| Ok((row.get_unwrap(0), row.get_unwrap(1)))) - .expect("query succeeds"); - let repo_name: String = connection - .query_row("select repo_name from repos where id=?1", [repo_id], |row| row.get(0)) - .expect("query succeeds"); - let now = SystemTime::now() .duration_since(UNIX_EPOCH) .expect("now is before epoch") .as_millis(); - let commit_sha: String = connection - .query_row("select sha from commits where id=?1", [job.commit_id], |row| row.get(0)) - .expect("can run query"); - std::mem::drop(connection); + let remote = dbctx.remote_by_id(job.remote_id).expect("query succeeds").expect("job has remote"); + let repo = dbctx.repo_by_id(remote.repo_id).expect("query succeeds").expect("remote has repo"); + + let commit_sha = dbctx.commit_sha(job.commit_id).expect("query succeeds"); let artifacts: PathBuf = reserve_artifacts_dir(run.id).expect("can reserve a directory for artifacts"); - eprintln!("running {}", repo_name); + eprintln!("running {}", &repo.name); - let res = candidate.submit(&dbctx, &run, &remote_git_url, &commit_sha).await; + let res = candidate.submit(&dbctx, &run, &remote.remote_git_url, &commit_sha).await; let mut client_job = match res { Ok(Some(mut client_job)) => { client_job } @@ -534,7 +525,9 @@ async fn main() { let dbctx = Arc::clone(&dbctx); spawn(async move { - find_client_task(dbctx, candidate); + let host_id = candidate.host_id; + let res = find_client_task(dbctx, candidate).await; + eprintln!("task client for {}: {:?}", host_id, res); }); } } diff --git a/src/dbctx.rs b/src/dbctx.rs index 4734229..ae06d21 100644 --- a/src/dbctx.rs +++ b/src/dbctx.rs @@ -292,7 +292,7 @@ impl DbCtx { pub fn remote_by_id(&self, id: u64) -> Result, String> { self.conn.lock() .unwrap() - .query_row("select * from remotes where id=?1", [id], |row| { + .query_row("select id, repo_id, remote_path, remote_api, remote_url, remote_git_url, notifier_config_path from remotes where id=?1", [id], |row| { let (id, repo_id, remote_path, remote_api, remote_url, remote_git_url, notifier_config_path) = row.try_into().unwrap(); Ok(Remote { -- cgit v1.1