diff --git a/Cargo.lock b/Cargo.lock index dc1985c..acbee04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -654,6 +654,10 @@ dependencies = [ "version_check 0.9.2", ] +[[package]] +name = "executor" +version = "0.1.0" + [[package]] name = "eyre" version = "0.6.1" diff --git a/Cargo.toml b/Cargo.toml index 03a33f6..e0cc07b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,5 +46,6 @@ features = [ "blocking" ] [workspace] members = [ + "./executor", "./lib/rocket_upload" ] diff --git a/executor/Cargo.toml b/executor/Cargo.toml new file mode 100644 index 0000000..dae0ef4 --- /dev/null +++ b/executor/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "executor" +version = "0.1.0" +authors = ["Christine Dodrill "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/executor/src/main.rs b/executor/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/executor/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/migrations/2020-10-31-003309_executions/down.sql b/migrations/2020-10-31-003309_executions/down.sql new file mode 100644 index 0000000..291a97c --- /dev/null +++ b/migrations/2020-10-31-003309_executions/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` \ No newline at end of file diff --git a/migrations/2020-10-31-003309_executions/up.sql b/migrations/2020-10-31-003309_executions/up.sql new file mode 100644 index 0000000..9d02f9d --- /dev/null +++ b/migrations/2020-10-31-003309_executions/up.sql @@ -0,0 +1,18 @@ +CREATE TABLE IF NOT EXISTS executions + ( id UUID DEFAULT uuid_generate_v4() NOT NULL + , handler_id UUID NOT NULL + , finished BOOLEAN NOT NULL DEFAULT false + , stderr VARCHAR + , created_at TIMESTAMP NOT NULL DEFAULT NOW() + , updated_at TIMESTAMP NOT NULL DEFAULT NOW() + , execution_time INTEGER -- XXX(Cadey): change this when you need handlers to run longer than 22 days + , PRIMARY KEY (id) + , CONSTRAINT fk_handler_id + FOREIGN KEY (handler_id) + REFERENCES handlers(id) + ); + +CREATE TRIGGER set_timestamp_executions + BEFORE UPDATE ON executions + FOR EACH ROW + EXECUTE PROCEDURE trigger_set_timestamp(); diff --git a/scripts/devel_db.sh b/scripts/devel_db.sh index cb4615a..fae2c77 100755 --- a/scripts/devel_db.sh +++ b/scripts/devel_db.sh @@ -3,6 +3,7 @@ set -e set -x +docker rm -f wasmcloud-postgres ||: docker \ run \ --name wasmcloud-postgres \ @@ -11,3 +12,5 @@ docker \ -p 5432:5432 \ -d \ postgres:alpine +sleep 2 +diesel migration run diff --git a/shell.nix b/shell.nix index 5222d60..4c3633a 100644 --- a/shell.nix +++ b/shell.nix @@ -3,7 +3,8 @@ let rust = import ./nix/rust.nix { inherit sources; }; pkgs = import sources.nixpkgs { }; in pkgs.mkShell rec { - buildInputs = with pkgs; [ + buildInputs = with pkgs; with elmPackages; [ + # rust rust diesel-cli postgresql @@ -11,6 +12,11 @@ in pkgs.mkShell rec { cargo-watch pkg-config openssl + + # elm + elm2nix + elm + elm-language-server ]; B2_CREDFILE = "./var/secret/b2-creds.txt"; diff --git a/src/models.rs b/src/models.rs index 5c990d8..b2f1d7b 100644 --- a/src/models.rs +++ b/src/models.rs @@ -102,3 +102,24 @@ pub struct HandlerConfig { pub created_at: NaiveDateTime, pub updated_at: NaiveDateTime, } + +#[derive(Insertable)] +#[table_name = "executions"] +pub struct NewExecution { + pub handler_id: Uuid, + pub finished: bool, + pub stderr: Option, + pub execution_time: i32, +} + +#[derive(Queryable, Debug, Clone, Serialize)] +pub struct Execution { + pub id: Uuid, + pub handler_id: Uuid, + pub finished: bool, + pub stderr: Option, + pub execution_time: i32, + + pub created_at: NaiveDateTime, + pub updated_at: NaiveDateTime, +} diff --git a/src/schema.rs b/src/schema.rs index 8a669fd..2690c34 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1,3 +1,15 @@ +table! { + executions (id) { + id -> Uuid, + handler_id -> Uuid, + finished -> Bool, + stderr -> Nullable, + created_at -> Timestamp, + updated_at -> Timestamp, + execution_time -> Nullable, + } +} + table! { gitea_tokens (id) { id -> Uuid, @@ -55,9 +67,8 @@ table! { } } -joinable!(handler_config -> handlers (handler_id)); - allow_tables_to_appear_in_same_query!( + executions, gitea_tokens, handler_config, handlers,