Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rustworthy committed Aug 14, 2024
1 parent 0e85a61 commit 93fcdc0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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:
Expand Down
33 changes: 31 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/worker/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ impl<E: 'static> WorkerBuilder<E> {
/// 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`.
Expand All @@ -269,6 +274,11 @@ impl<E: 'static> WorkerBuilder<E> {

/// 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`.
Expand Down

0 comments on commit 93fcdc0

Please sign in to comment.