From 23010c9512331b2e8f03531a991d2c91a29d2589 Mon Sep 17 00:00:00 2001 From: Diggory Blake Date: Mon, 29 Mar 2021 22:33:07 +0100 Subject: [PATCH] Add CI --- .github/workflows/publish.yml | 24 ++++++++++ .github/workflows/toolchain.yml | 78 +++++++++++++++++++++++++++++++++ Cargo.toml | 8 +++- src/lib.rs | 35 +++++++++++++-- 4 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/toolchain.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..cdbe2b3 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,24 @@ +on: + release: + types: [published] + +name: Publish + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: login + args: -- ${{secrets.CARGO_TOKEN}} + - uses: actions-rs/cargo@v1 + with: + command: publish diff --git a/.github/workflows/toolchain.yml b/.github/workflows/toolchain.yml new file mode 100644 index 0000000..eea4c71 --- /dev/null +++ b/.github/workflows/toolchain.yml @@ -0,0 +1,78 @@ +on: [push, pull_request] + +name: CI + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: check + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add clippy + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings + + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: test + + test_nightly: + name: Test (Nightly) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + - uses: actions-rs/cargo@v1 + with: + command: test diff --git a/Cargo.toml b/Cargo.toml index aef6842..d89000d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,10 @@ name = "sqlxmq" version = "0.1.0" authors = ["Diggory Blake "] edition = "2018" +license = "MIT OR Apache-2.0" +repository = "https://github.com/Diggsey/sqlxmq" +description = "A reliable job queue using PostgreSQL as a backing store" +readme = "README.md" [workspace] members = ["sqlxmq_macros"] @@ -12,13 +16,12 @@ members = ["sqlxmq_macros"] [dependencies] sqlx = { version = "0.5.1", features = [ "postgres", - "runtime-async-std-native-tls", + "runtime-tokio-native-tls", "chrono", "uuid", ] } tokio = { version = "1.3.0", features = ["full"] } dotenv = "0.15.0" -futures = "0.3.13" chrono = "0.4.19" uuid = { version = "0.8.2", features = ["v4"] } log = "0.4.14" @@ -29,3 +32,4 @@ sqlxmq_macros = { version = "0.1", path = "sqlxmq_macros" } [dev-dependencies] dotenv = "0.15.0" pretty_env_logger = "0.4.0" +futures = "0.3.13" diff --git a/src/lib.rs b/src/lib.rs index 05171e1..38dc14f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,13 +110,15 @@ //! The first step is to define a function to be run on the job queue. //! //! ```rust +//! use std::error::Error; +//! //! use sqlxmq::{job, CurrentJob}; //! //! // Arguments to the `#[job]` attribute allow setting default job options. //! #[job(channel_name = "foo")] //! async fn example_job( //! mut current_job: CurrentJob, -//! ) -> sqlx::Result<()> { +//! ) -> Result<(), Box> { //! // Decode a JSON payload //! let who: Option = current_job.json()?; //! @@ -135,9 +137,22 @@ //! Next we need to create a job runner: this is what listens for new jobs //! and executes them. //! -//! ```rust +//! ```rust,no_run +//! use std::error::Error; +//! //! use sqlxmq::JobRegistry; //! +//! # use sqlxmq::{job, CurrentJob}; +//! # +//! # #[job] +//! # async fn example_job( +//! # current_job: CurrentJob, +//! # ) -> Result<(), Box> { Ok(()) } +//! # +//! # async fn connect_to_db() -> sqlx::Result> { +//! # unimplemented!() +//! # } +//! //! #[tokio::main] //! async fn main() -> Result<(), Box> { //! // You'll need to provide a Postgres connection pool. @@ -160,6 +175,7 @@ //! //! // The job runner will continue listening and running //! // jobs until `runner` is dropped. +//! Ok(()) //! } //! ``` //! @@ -168,12 +184,25 @@ //! The final step is to actually run a job. //! //! ```rust +//! # use std::error::Error; +//! # use sqlxmq::{job, CurrentJob}; +//! # +//! # #[job] +//! # async fn example_job( +//! # current_job: CurrentJob, +//! # ) -> Result<(), Box> { Ok(()) } +//! # +//! # async fn example( +//! # pool: sqlx::Pool +//! # ) -> Result<(), Box> { //! example_job.new() //! // This is where we override job configuration //! .set_channel_name("bar") -//! .set_json("John") +//! .set_json("John")? //! .spawn(&pool) //! .await?; +//! # Ok(()) +//! # } //! ``` #[doc(hidden)]