### Synchronize README with Cargo Docs Source: https://github.com/diggsey/sqlxmq/blob/master/README.md Provides instructions on how to keep the project's README file synchronized with its crate documentation. It explains the use of the `cargo-sync-readme` tool and how to install it if it's not already available. ```bash cargo sync-readme # (make sure the cargo command is installed): # cargo install cargo-sync-readme ``` -------------------------------- ### Listen for Jobs with sqlxmq Runner Source: https://github.com/diggsey/sqlxmq/blob/master/README.md Demonstrates setting up a job runner to listen for new jobs. It covers connecting to a PostgreSQL database, constructing a job registry, configuring the runner's concurrency, and starting the background listening process. The runner continues until it is dropped. ```rust use std::error::Error; use sqlxmq::JobRegistry; #[tokio::main] async fn main() -> Result<(), Box> { // You'll need to provide a Postgres connection pool. let pool = connect_to_db().await?; // Construct a job registry from our single job. let mut registry = JobRegistry::new(&[example_job]); // Here is where you can configure the registry // registry.set_error_handler(...) // And add context registry.set_context("Hello"); let runner = registry // Create a job runner using the connection pool. .runner(&pool) // Here is where you can configure the job runner // Aim to keep 10-20 jobs running at a time. .set_concurrency(10, 20) // Start the job runner in the background. .run() .await?; // The job runner will continue listening and running // jobs until `runner` is dropped. Ok(()) } ``` -------------------------------- ### Define a Job with sqlxmq Source: https://github.com/diggsey/sqlxmq/blob/master/README.md Example of defining a background job function using the `#[job]` attribute macro in Rust. It shows how to define channel names, handle job arguments, access job context, and complete the job. ```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( // The first argument should always be the current job. mut current_job: CurrentJob, // Additional arguments are optional, but can be used to access context // provided via [`JobRegistry::set_context`]. message: &'static str, ) -> Result<(), Box> { // Decode a JSON payload let who: Option = current_job.json()?; // Do some work println!("{}, {}!", message, who.as_deref().unwrap_or("world")); // Mark the job as complete current_job.complete().await?; Ok(()) } ``` -------------------------------- ### Spawn a Job with sqlxmq Source: https://github.com/diggsey/sqlxmq/blob/master/README.md Illustrates the process of spawning a new job. This involves using a job builder to configure specific job parameters, such as the channel name and JSON payload, before dispatching it to be run asynchronously. ```rust example_job.builder() // This is where we can override job configuration .set_channel_name("bar") .set_json("John")? // Assuming 'John' is a serializable type .spawn(&pool) .await?; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.