dynamodb_lease/lib.rs
1//! Client that acquires distributed locks with an expiry (aka "leases") using dynamodb & tokio runtime.
2//!
3//! # Example
4//! ```
5//! # use std::time::Duration;
6//! # async fn foo() -> anyhow::Result<()> {
7//! # let dynamodb_client: aws_sdk_dynamodb::Client = unimplemented!();
8//! let client = dynamodb_lease::Client::builder()
9//! .table_name("example-leases")
10//! .lease_ttl_seconds(60)
11//! .build_and_check_db(dynamodb_client)
12//! .await?;
13//!
14//! // acquire a lease for "important-job-123"
15//! // waits for any other holders to release if necessary
16//! let lease = client.acquire("important-job-123").await?;
17//!
18//! // `lease` periodically extends itself in a background tokio task
19//!
20//! // until dropped others will not be able to acquire this lease
21//! assert!(client.try_acquire("important-job-123").await?.is_none());
22//!
23//! // Dropping the lease will asynchronously release it, so others may acquire it
24//! drop(lease);
25//! # Ok(()) }
26//! ```
27
28mod builder;
29mod client;
30mod lease;
31mod local;
32
33pub use builder::ClientBuilder;
34pub use client::Client;
35pub use lease::Lease;