From 93fcdc0657e341543ee36b57bbbd37bb14d4e8df Mon Sep 17 00:00:00 2001 From: Pavel Mikhalkevich Date: Wed, 14 Aug 2024 16:29:53 +0400 Subject: [PATCH] Update docs --- README.md | 4 +++- src/lib.rs | 33 +++++++++++++++++++++++++++++++-- src/worker/builder.rs | 10 ++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 86ea74f4..0fc5ae72 100644 --- a/README.md +++ b/README.md @@ -78,11 +78,12 @@ let mut w = Worker::builder() println!("{:?}", job); Ok::<(), io::Error>(()) }) - .register_blocking_fn("fibo", |job| + .register_blocking_fn("fibo", |job| { std::thread::sleep(Duration::from_millis(1000)); println!("{:?}", job); Ok::<(), io::Error>(()) }) + .with_rustls() // available on `rustls` feature only .connect(None) .await .unwrap(); @@ -96,6 +97,7 @@ match w.run(&["default"]).await { stop_details.workers_still_running ); } +} ``` Also see some usage examples in `examples` directory in the project's root. You can run an example with: diff --git a/src/lib.rs b/src/lib.rs index 1f2c06c3..30ed5c10 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,14 +48,43 @@ //! //! ```no_run //! # tokio_test::block_on(async { -//! use faktory::Worker; +//! use async_trait::async_trait; +//! use faktory::{Job, JobRunner, Worker}; //! use std::io; +//! +//! struct DomainEntity(i32); +//! +//! impl DomainEntity { +//! fn new(buzz: i32) -> Self { +//! DomainEntity(buzz) +//! } +//! } +//! +//! #[async_trait] +//! impl JobRunner for DomainEntity { +//! type Error = io::Error; +//! +//! async fn run(&self, job: Job) -> Result<(), Self::Error> { +//! println!("{:?}, buzz={}", job, self.0); +//! Ok(()) +//! } +//! } +//! //! let mut w = Worker::builder() +//! .register("fizz", DomainEntity::new(1)) //! .register_fn("foobar", |job| async move { //! println!("{:?}", job); //! Ok::<(), io::Error>(()) //! }) -//! .connect(None).await.unwrap(); +//! .register_blocking_fn("fibo", |job| { +//! std::thread::sleep(std::time::Duration::from_millis(1000)); +//! println!("{:?}", job); +//! Ok::<(), io::Error>(()) +//! }) +//! .with_rustls() // available on `rustls` feature only +//! .connect(None) +//! .await +//! .unwrap(); //! //! if let Err(e) = w.run(&["default"]).await { //! println!("worker failed: {}", e); diff --git a/src/worker/builder.rs b/src/worker/builder.rs index 3bbfcd82..f81d5500 100644 --- a/src/worker/builder.rs +++ b/src/worker/builder.rs @@ -257,6 +257,11 @@ impl WorkerBuilder { /// The underlying crate (`native-tls`) will use _SChannel_ on Windows, /// _SecureTransport_ on OSX, and _OpenSSL_ on other platforms. /// + /// Internally, will use [`TlsStream::connect`](crate::native_tls::TlsStream::connect) to establish + /// a TLS stream to the Faktory server. If [`WorkerBuilder::dangerously_skip_verify_server_certs`] + /// has been called on this builder, [`TlsStream::connect_dangerously_skipping_verification`](crate::native_tls::TlsStream::connect_dangerously_skipping_verification) + /// will be used. + /// /// Note that if you use this method on the builder, but eventually use [`WorkerBuilder::connect_with`] /// (rather than [`WorkerBuilder::connect`]) to create an instance of [`Worker`], this worker /// will be connected to the Faktory server with the stream you've provided to `connect_with`. @@ -269,6 +274,11 @@ impl WorkerBuilder { /// Make the traffic between this worker and Faktory encrypted with [`rustls`](https://github.com/rustls/rustls). /// + /// Internally, will use [`TlsStream::connect_with_native_certs`](crate::rustls::TlsStream::connect_with_native_certs) + /// to establish a TLS stream to the Faktory server. If [`WorkerBuilder::dangerously_skip_verify_server_certs`] + /// has been called on this builder, a `true` will provided to [`TlsStream::connect_with_native_certs`](crate::rustls::TlsStream::connect_with_native_certs) + /// as an argument for `dangerously_skip_verify`. + /// /// Note that if you use this method on the builder, but eventually use [`WorkerBuilder::connect_with`] /// (rather than [`WorkerBuilder::connect`]) to create an instance of [`Worker`], this worker /// will be connected to the Faktory server with the stream you've provided to `connect_with`.