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)]