Skip to content

Commit

Permalink
Merge pull request #5 from insipx/insipx/update-sqlx
Browse files Browse the repository at this point in the history
update sqlx to 0.5
  • Loading branch information
insipx committed Feb 8, 2021
2 parents bb552d7 + 50f45af commit 13b3fa3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion coil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 14 additions & 16 deletions coil/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct BackgroundJob {
pub data: Vec<u8>,
pub is_async: bool,
}

/// Run the migrations for the background tasks.
/// This creates a table _background_tasks which stores the tasks for execution
/// ```sql
Expand All @@ -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<T: Job>(
conn: impl Executor<'_, Database = Postgres>,
Expand All @@ -61,7 +61,10 @@ pub async fn enqueue_job<T: 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(())
}

Expand All @@ -80,16 +83,19 @@ pub async fn enqueue_job<T: Job>(
Ok(())
}

pub async fn enqueue_jobs_batch<T: Job>(conn: &mut sqlx::PgConnection, jobs: Vec<T>) -> Result<(), EnqueueError> {
pub async fn enqueue_jobs_batch<T: Job>(
conn: &mut sqlx::PgConnection,
jobs: Vec<T>,
) -> 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)?;
Expand Down Expand Up @@ -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<i64, EnqueueError> {
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(
Expand Down
5 changes: 4 additions & 1 deletion coil/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let
moz_overlay = (import "/home/insipx/.config/nixpkgs/overlays/rust-overlay.nix");
nixpkgs = import <nixpkgs> { 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;
Expand Down

0 comments on commit 13b3fa3

Please sign in to comment.