Skip to content

Commit b092145

Browse files
committed
Add README files for rustapi-jobs and rustapi-testing
Introduces documentation for the rustapi-jobs and rustapi-testing crates, outlining their features, usage, and example code to help users get started with background job processing and testing utilities for the RustAPI framework.
1 parent 392aa0f commit b092145

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

crates/rustapi-jobs/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# RustAPI Jobs
2+
3+
Robust background job processing for the RustAPI framework.
4+
5+
## Features
6+
7+
- **Multiple Backends**: Support for Redis and PostgreSQL backends.
8+
- **Reliable Processing**: At-least-once delivery guarantees.
9+
- **Retries**: Configurable retry policies with exponential backoff.
10+
- **Scheduled Tasks**: Cron-like scheduling for recurring jobs.
11+
- **Async Processing**: Fully async/await based on Tokio.
12+
13+
## Usage
14+
15+
Add to your `Cargo.toml`:
16+
17+
```toml
18+
[dependencies]
19+
rustapi-jobs = { version = "0.1", features = ["redis"] }
20+
```
21+
22+
### Defining a Job
23+
24+
```rust
25+
use rustapi_jobs::{Job, JobContext};
26+
use serde::{Serialize, Deserialize};
27+
28+
#[derive(Serialize, Deserialize)]
29+
struct EmailJob {
30+
to: String,
31+
subject: String,
32+
body: String,
33+
}
34+
35+
#[async_trait]
36+
impl Job for EmailJob {
37+
const NAME: &'static str = "send_email";
38+
39+
async fn run(&self, _ctx: JobContext) -> Result<(), Error> {
40+
// Send email...
41+
Ok(())
42+
}
43+
}
44+
```
45+
46+
### Enqueueing Jobs
47+
48+
```rust
49+
let queue = RedisQueue::new("redis://localhost:6379").await?;
50+
queue.push(EmailJob {
51+
to: "user@example.com".to_string(),
52+
subject: "Welcome!".to_string(),
53+
body: "Hello...".to_string(),
54+
}).await?;
55+
```

crates/rustapi-testing/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# RustAPI Testing
2+
3+
Testing utilities and test harness for the RustAPI framework.
4+
5+
## Features
6+
7+
- **TestClient**: A wrapper around `reqwest` and `hyper` for testing your API endpoints integration.
8+
- **Fluid Assertions**: Custom matchers for status codes, headers, and body content.
9+
- **Mocking**: Helpers for mocking dependencies (if applicable).
10+
- **Proptest Integration**: Strategies for property-based testing of handlers.
11+
12+
## Usage
13+
14+
Add to `dev-dependencies`:
15+
16+
```toml
17+
[dev-dependencies]
18+
rustapi-testing = "0.1"
19+
```
20+
21+
### Example
22+
23+
```rust
24+
use rustapi_testing::TestClient;
25+
use rustapi::status::StatusCode;
26+
27+
#[tokio::test]
28+
async fn test_create_user() {
29+
let client = TestClient::new(app());
30+
31+
let res = client.post("/users")
32+
.json(&json!({ "name": "Alice" }))
33+
.send()
34+
.await;
35+
36+
res.assert_status(StatusCode::OK);
37+
res.assert_json_snapshot!("create_user_response");
38+
}
39+
```

0 commit comments

Comments
 (0)