File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ ```
Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments