From 1558a2817081d9110eff20f5d429125e460d9a81 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 13 Nov 2020 17:21:57 +0100 Subject: Add uuid field to "job" table Signed-off-by: Matthias Beyer --- migrations/2020-11-13-161449_add_job_uuid/down.sql | 5 +++++ migrations/2020-11-13-161449_add_job_uuid/up.sql | 5 +++++ src/commands/db.rs | 4 ++-- src/db/models/job.rs | 4 ++++ src/endpoint/scheduler.rs | 2 +- src/schema.rs | 1 + 6 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 migrations/2020-11-13-161449_add_job_uuid/down.sql create mode 100644 migrations/2020-11-13-161449_add_job_uuid/up.sql diff --git a/migrations/2020-11-13-161449_add_job_uuid/down.sql b/migrations/2020-11-13-161449_add_job_uuid/down.sql new file mode 100644 index 0000000..d775ff6 --- /dev/null +++ b/migrations/2020-11-13-161449_add_job_uuid/down.sql @@ -0,0 +1,5 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE + jobs +DROP COLUMN + uuid diff --git a/migrations/2020-11-13-161449_add_job_uuid/up.sql b/migrations/2020-11-13-161449_add_job_uuid/up.sql new file mode 100644 index 0000000..798a1b6 --- /dev/null +++ b/migrations/2020-11-13-161449_add_job_uuid/up.sql @@ -0,0 +1,5 @@ +-- Your SQL goes here +ALTER TABLE + jobs +ADD COLUMN + uuid UUID NOT NULL UNIQUE diff --git a/src/commands/db.rs b/src/commands/db.rs index 087cd85..c96ef7b 100644 --- a/src/commands/db.rs +++ b/src/commands/db.rs @@ -213,7 +213,7 @@ fn jobs(conn_cfg: DbConnectionConfig, matches: &ArgMatches) -> Result<()> { use crate::schema::jobs::dsl; let csv = matches.is_present("csv"); - let hdrs = mk_header(vec!["id", "submit uuid", "time", "endpoint", "success"]); + let hdrs = mk_header(vec!["id", "submit uuid", "job uuid", "time", "endpoint", "success"]); let conn = crate::db::establish_connection(conn_cfg)?; let jobs = matches.value_of("submit_uuid") .map(uuid::Uuid::parse_str) @@ -244,7 +244,7 @@ fn jobs(conn_cfg: DbConnectionConfig, matches: &ArgMatches) -> Result<()> { }) .unwrap_or_else(|| String::from("unknown")); - Ok(vec![format!("{}", job.id), submit.uuid.to_string(), submit.submit_time.to_string(), ep.name, success]) + Ok(vec![format!("{}", job.id), submit.uuid.to_string(), job.uuid.to_string(), submit.submit_time.to_string(), ep.name, success]) }) .collect::>>()?; diff --git a/src/db/models/job.rs b/src/db/models/job.rs index fd3b862..12fba7b 100644 --- a/src/db/models/job.rs +++ b/src/db/models/job.rs @@ -19,6 +19,7 @@ pub struct Job { pub container_hash: String, pub script_text: String, pub log_text: String, + pub uuid: ::uuid::Uuid, } #[derive(Debug, Insertable)] @@ -31,10 +32,12 @@ struct NewJob<'a> { pub container_hash: &'a str, pub script_text: &'a str, pub log_text: &'a str, + pub uuid: &'a ::uuid::Uuid, } impl Job { pub fn create(database_connection: &PgConnection, + job_uuid: &::uuid::Uuid, submit: &Submit, endpoint: &Endpoint, package: &Package, @@ -44,6 +47,7 @@ impl Job { log: &str, ) -> Result<()> { let new_job = NewJob { + uuid: job_uuid, submit_id: submit.id, endpoint_id: endpoint.id, package_id: package.id, diff --git a/src/endpoint/scheduler.rs b/src/endpoint/scheduler.rs index 6bbb438..541082a 100644 --- a/src/endpoint/scheduler.rs +++ b/src/endpoint/scheduler.rs @@ -151,7 +151,7 @@ impl JobHandle { let log = logres.with_context(|| anyhow!("Collecting logs for job on '{}'", ep.name()))?; let (paths, container_hash, script) = res.with_context(|| anyhow!("Running job on '{}'", ep.name()))?; - dbmodels::Job::create(&self.db, &self.submit, &endpoint, &package, &image, &container_hash, &script, &log)?; + dbmodels::Job::create(&self.db, &job_id, &self.submit, &endpoint, &package, &image, &container_hash, &script, &log)?; Ok(paths) } diff --git a/src/schema.rs b/src/schema.rs index 0baaf47..aa777a6 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -68,6 +68,7 @@ table! { container_hash -> Varchar, script_text -> Text, log_text -> Text, + uuid -> Uuid, } } -- cgit v1.2.3