From 2751299d9812a22b8629e837942ce07baea6b49a Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Mon, 8 Feb 2021 16:31:46 +0100 Subject: [PATCH 1/3] update sqlx to 0.5 --- coil/Cargo.toml | 2 +- integration_tests/Cargo.toml | 2 +- shell.nix | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/coil/Cargo.toml b/coil/Cargo.toml index ab5d84d..fb4440a 100644 --- a/coil/Cargo.toml +++ b/coil/Cargo.toml @@ -15,7 +15,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -sqlx = { version = "0.4.0-beta.1", features = ["postgres"] } +sqlx = { version = "0.5", default-features = false, features = ["postgres", "macros", "runtime-async-std-rustls", "migrate"] } rayon = "1.3" serde = "1.0" rmp-serde = "0.14" diff --git a/integration_tests/Cargo.toml b/integration_tests/Cargo.toml index bd33ec2..0b8eeaf 100644 --- a/integration_tests/Cargo.toml +++ b/integration_tests/Cargo.toml @@ -9,7 +9,7 @@ autotests = false [dependencies] coil = { path = "../coil", features = ["test_components"] } -sqlx = { version = "0.4.0-beta.1", features = ["postgres"] } +sqlx = { version = "0.5", default-features = false, features = ["postgres", "macros", "runtime-async-std-rustls", "migrate"] } serde = { version = "1.0", features = ["derive"] } smol = "0.3.3" futures = "0.3.5" diff --git a/shell.nix b/shell.nix index dee5480..4a109a6 100644 --- a/shell.nix +++ b/shell.nix @@ -2,7 +2,7 @@ let moz_overlay = (import "/home/insipx/.config/nixpkgs/overlays/rust-overlay.nix"); nixpkgs = import { overlays = [ moz_overlay ]; }; unstable = import (fetchTarball "channel:nixos-unstable") {}; - rustnightly = ((nixpkgs.rustChannelOf { date = "2020-08-17"; channel = "nightly"; }).rust.override { extensions = [ "rust-src" "rust-analysis" "rustfmt-preview" ]; targets = ["wasm32-unknown-unknown"]; }); + rustnightly = ((nixpkgs.rustChannelOf { date = "2021-01-31"; channel = "nightly"; }).rust.override { extensions = [ "rust-src" "rust-analysis" "rustfmt-preview" ]; targets = ["wasm32-unknown-unknown"]; }); in with nixpkgs; From ef7ef5b7636736aac629110e8d65dd986ee7c7be Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Mon, 8 Feb 2021 16:32:27 +0100 Subject: [PATCH 2/3] add dependabot --- .github/dependabot.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..9152892 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,13 @@ +version: 2 +updates: + - package-ecosystem: "cargo" + directory: "/" + # Handle updates for crates from github.com/paritytech/substrate + # and github.com/paritytech/polkadot manually. + schedule: + interval: "daily" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" From 50f45af3c21d8ff1af8540ca2d7df52387b2600b Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Mon, 8 Feb 2021 16:36:27 +0100 Subject: [PATCH 3/3] forbid unsafe, deny dead code --- coil/src/db.rs | 30 ++++++++++++++---------------- coil/src/lib.rs | 5 ++++- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/coil/src/db.rs b/coil/src/db.rs index 2754409..d3e443f 100644 --- a/coil/src/db.rs +++ b/coil/src/db.rs @@ -28,7 +28,7 @@ pub struct BackgroundJob { pub data: Vec, pub is_async: bool, } - + /// Run the migrations for the background tasks. /// This creates a table _background_tasks which stores the tasks for execution /// ```sql @@ -48,7 +48,7 @@ pub async fn migrate(pool: impl Acquire<'_, Database = Postgres>) -> Result<(), .await .map_err(Into::into) } - + #[cfg(feature = "analyze")] pub async fn enqueue_job( conn: impl Executor<'_, Database = Postgres>, @@ -61,7 +61,10 @@ pub async fn enqueue_job( .bind(T::ASYNC) .fetch_one(conn) .await?; - log::debug!("EXPLAIN/ANALYZE {}", serde_json::to_string_pretty(&res.0.0).unwrap()); + log::debug!( + "EXPLAIN/ANALYZE {}", + serde_json::to_string_pretty(&res.0 .0).unwrap() + ); Ok(()) } @@ -80,16 +83,19 @@ pub async fn enqueue_job( Ok(()) } -pub async fn enqueue_jobs_batch(conn: &mut sqlx::PgConnection, jobs: Vec) -> Result<(), EnqueueError> { +pub async fn enqueue_jobs_batch( + conn: &mut sqlx::PgConnection, + jobs: Vec, +) -> Result<(), EnqueueError> { let mut batch = crate::batch::Batch::new( "jobs", - r#"INSERT INTO "_background_tasks" ( + r#"INSERT INTO "_background_tasks" ( job_type, data, is_async ) VALUES "#, - r#""# + r#""#, ); - + for job in jobs.into_iter() { let data = rmp_serde::encode::to_vec(&job)?; batch.reserve(3)?; @@ -162,15 +168,7 @@ pub async fn update_failed_job( .await?; Ok(()) } -/* -pub async fn unlocked_tasks_count(conn: impl Executor<'_, Database = Postgres>, is_async: bool) -> Result { - let count = sqlx::query_as::<_, (i64,)>("SELECT COUNT(*) FROM _background_tasks WHERE is_async = $1") - .bind(is_async) - .fetch_one(conn) - .await?; - Ok(count.0) -} -*/ + /// Gets jobs which failed #[cfg(any(test, feature = "test_components"))] pub async fn failed_job_count( diff --git a/coil/src/lib.rs b/coil/src/lib.rs index 295948b..3668861 100644 --- a/coil/src/lib.rs +++ b/coil/src/lib.rs @@ -22,12 +22,15 @@ //! - SQL queries in `coil` are ran asynchronously wherever possible //! - Migrations are stored in the binary, and accessible via a `migrate()` fn. No more needing to copy-paste migration files! +#![forbid(unsafe_code)] +#![deny(dead_code)] + +mod batch; mod db; mod error; mod job; mod registry; mod runner; -mod batch; #[doc(hidden)] pub extern crate async_trait;