Capstone reliable task service
Quick answer
The capstone combines validated domain input, bounded admission, duplicate detection and explicit lifecycle decisions. Build a small task service incrementally, starting with a deterministic in-memory core.
Project milestones and acceptance criteria
Define a submit contract with scoped task IDs and immutable payloads; a repeated ID with the same payload returns the prior outcome, while a different payload is rejected. Separate domain and storage, use bounded workers, persist accepted work and completion, and design recovery with idempotent effects. Add HTTP and authentication only after core tests; add readiness, deadline-aware shutdown, redacted telemetry and container release checks. The first example is a deliberately bounded single-owner model, not an HTTP server or durable implementation. The second models retry classification. Acceptance tests should cover empty input, duplicates, conflicts, full capacity, restart recovery, lost acknowledgements and graceful draining; the last three require real integration tests.
use std::collections::HashMap;struct Service { jobs: HashMap<u64, String>, limit: usize }impl Service { fn submit(&mut self, id: u64, body: &str) -> &'static str { if body.trim().is_empty() || body.len() > 256 { return "invalid"; } if let Some(old) = self.jobs.get(&id) { return if old == body { "repeat" } else { "conflict" }; } if self.jobs.len() >= self.limit { return "full"; } self.jobs.insert(id, body.to_owned()); "accepted" }}fn main() { let mut s = Service { jobs: HashMap::new(), limit: 1 }; for (id, body) in [(1, ""), (1, "build"), (1, "build"), (1, "other"), (2, "test")] { println!("{}", s.submit(id, body)); }}Expected stdout (not executed):
invalidacceptedrepeatconflictfullThis capacity bounds retained records, not just pending jobs; production retention and queue capacity must be separate.
#[derive(Clone, Copy)]enum Outcome { Accepted, Conflict, Busy }fn retryable(outcome: Outcome, budget: u8) -> bool { budget > 0 && matches!(outcome, Outcome::Busy)}fn main() { println!("{} {} {} {}", retryable(Outcome::Accepted, 1), retryable(Outcome::Conflict, 1), retryable(Outcome::Busy, 1), retryable(Outcome::Busy, 0));}Expected stdout (not executed):
false false true falseRetrying Busy still requires an appropriate delay and deadline and a safe request identity.
Common mistake
Do not call this model production-ready: it lacks persistence, authorization, real workers, network handling and integration tests.
Try it yourself
Implement the next milestone as a local library with unit tests, then a transactional store adapter; document failure behavior before adding an HTTP endpoint.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Capstone reliable task service — practice quiz
Choose one answer per question. Code examples are predictions; review explanations after attempting them.
A task service keeps accepted IDs only in memory. Which test cannot establish durability using that model alone?
Capstone reliable task service — example 1. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```rust use std::collections::HashMap; struct Service { jobs: HashMap<u64, String>, limit: usize } impl Service { fn submit(&mut self, id: u64, body: &str) -> &'static str { if body.trim().is_empty() || body.len() > 256 { return "invalid"; } if let Some(old) = self.jobs.get(&id) { return if old == body { "repeat" } else { "conflict" }; } if self.jobs.len() >= self.limit { return "full"; } self.jobs.insert(id, body.to_owned()); "accepted" } } fn main() { let mut s = Service { jobs: HashMap::new(), limit: 1 }; for (id, body) in [(1, ""), (1, "build"), (1, "build"), (1, "other"), (2, "test")] { println!("{}", s.submit(id, body)); } } ``` What standard output should the program produce if its run succeeds? Ignore Cargo and diagnostic messages.
Capstone reliable task service — example 2. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```rust #[derive(Clone, Copy)] enum Outcome { Accepted, Conflict, Busy } fn retryable(outcome: Outcome, budget: u8) -> bool { budget > 0 && matches!(outcome, Outcome::Busy) } fn main() { println!("{} {} {} {}", retryable(Outcome::Accepted, 1), retryable(Outcome::Conflict, 1), retryable(Outcome::Busy, 1), retryable(Outcome::Busy, 0)); } ``` What standard output should the program produce if its run succeeds? Ignore Cargo and diagnostic messages.