Skip to content

Commit a9b3c0b

Browse files
docs: update versions to 0.1.233, expand cookbook, and fix oauth2 test panic
- Updated `docs/GETTING_STARTED.md` and `docs/cookbook/src/getting_started/installation.md` to reference version `0.1.233`. - Expanded `docs/cookbook/src/learning/README.md` with an internal learning path. - Added code examples to `docs/cookbook/src/crates/rustapi_jobs.md` and documentation for `insight` in `rustapi_extras`. - Fixed a panic in `rustapi-extras` property tests (`oauth2::tokens::property_tests::prop_token_expiration_tracking`) caused by subtraction overflow. Co-authored-by: Tuntii <121901995+Tuntii@users.noreply.github.com>
1 parent 48fd787 commit a9b3c0b

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

crates/rustapi-extras/src/oauth2/tokens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ mod property_tests {
362362
// Remaining time should be close to expires_in (within a few seconds)
363363
let remaining_secs = remaining.unwrap().as_secs();
364364
prop_assert!(remaining_secs <= expires_in_secs);
365-
prop_assert!(remaining_secs >= expires_in_secs - 2); // Allow 2 sec tolerance
365+
prop_assert!(remaining_secs >= expires_in_secs.saturating_sub(2)); // Allow 2 sec tolerance
366366
}
367367

368368
/// Property 16: Token response builder pattern works correctly

docs/cookbook/src/crates/rustapi_extras.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ The `insight` feature provides powerful real-time traffic analysis and debugging
8989

9090
```toml
9191
[dependencies]
92-
rustapi-extras = { version = "0.1.233", features = ["insight"] }
92+
rustapi-extras = { version = "0.1", features = ["insight"] }
9393
```
9494

9595
### Setup
@@ -98,12 +98,11 @@ rustapi-extras = { version = "0.1.233", features = ["insight"] }
9898
use rustapi_extras::insight::{InsightLayer, InMemoryInsightStore, InsightConfig};
9999
use std::sync::Arc;
100100

101-
let store = Arc::new(InMemoryInsightStore::new(InMemoryInsightStore::default_capacity()));
101+
let store = Arc::new(InMemoryInsightStore::new());
102102
let config = InsightConfig::default();
103103

104104
let app = RustApi::new()
105-
.state(store.clone())
106-
.layer(InsightLayer::with_config(config).with_store(store.clone()));
105+
.layer(InsightLayer::new(config, store.clone()));
107106
```
108107

109108
### Accessing Data

docs/cookbook/src/crates/rustapi_jobs.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ struct EmailJob {
3131
#[async_trait::async_trait]
3232
impl Job for EmailJob {
3333
const NAME: &'static str = "email_job";
34-
type Data = EmailJob;
3534

36-
async fn execute(_ctx: JobContext, data: Self::Data) -> Result<()> {
37-
println!("Sending email to {} with subject: {}", data.to, data.subject);
35+
async fn run(&self, _ctx: JobContext) -> Result<()> {
36+
println!("Sending email to {} with subject: {}", self.to, self.subject);
3837
// Simulate work
3938
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
4039
Ok(())
@@ -58,15 +57,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
5857
let queue = JobQueue::new(backend);
5958

6059
// 3. Register the job type
61-
// `register_job` is async and expects a job handler instance, not a type parameter.
62-
queue.register_job(EmailJobHandler::new()).await?;
60+
queue.register_job::<EmailJob>();
6361

6462
// 4. Start the worker in the background
6563
let worker_queue = queue.clone();
6664
tokio::spawn(async move {
67-
if let Err(err) = worker_queue.start_worker().await {
68-
eprintln!("Job worker exited with error: {err}");
69-
}
65+
worker_queue.start_workers().await;
7066
});
7167

7268
// 5. Enqueue a job

0 commit comments

Comments
 (0)