Skip to content

Commit 63db9ba

Browse files
author
developerworks
committed
Restructure examples directory: rename demo to dashboard, add job/sidecar/worker patterns
- Rename examples/demo/ to examples/dashboard/ - Add job example with task-based lifecycle and observation - Add sidecar example with companion process pattern - Add worker example with background worker pattern - Add supervisor example with nested supervision tree - Update supervisor_examples_test to cover all example types
1 parent 9057190 commit 63db9ba

29 files changed

Lines changed: 2076 additions & 9 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async fn main() -> Result<(), rust_supervisor::error::types::SupervisorError> {
175175
## Examples
176176

177177
```bash
178-
cargo run --example demo -- --config examples/config/supervisor.yaml
178+
cargo run --example dashboard -- --config examples/config/supervisor.yaml
179179
cargo run --example supervisor_quickstart
180180
cargo run --example config_tree_supervisor
181181
cargo run --example restart_policy_lab
@@ -187,7 +187,7 @@ cargo run --example policy_failure_matrix
187187
cargo run --example diagnostic_replay
188188
```
189189

190-
`cargo run --example demo -- --config examples/config/supervisor.yaml` is the three-end supervisor demo. It starts the library-only supervisor runtime from the same configuration file, then starts the demo-only dashboard IPC service and registration heartbeat inside `examples/demo`. This entry point is not the production binary for the crate, and it does not write demo state into the core `src` modules.
190+
`cargo run --example dashboard -- --config examples/config/supervisor.yaml` is the three-end supervisor demo. It starts the library-only supervisor runtime from the same configuration file, then starts the demo-only dashboard IPC service and registration heartbeat inside `examples/dashboard`. This entry point is not the production binary for the crate, and it does not write demo state into the core `src` modules.
191191

192192
## Manuals
193193

examples/job/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Job Role Example
2+
3+
[中文说明](README.zh.md)
4+
5+
This example shows a one-shot `WorkRole::Job` child. A job role is intended for finite work that should finish and then stay stopped.
6+
7+
Run it with:
8+
9+
```bash
10+
cargo run --package rust-tokio-supervisor --example job
11+
```
12+
13+
## What It Shows
14+
15+
- Initialization: `job_task.rs` builds a `daily-report-job` child and marks it as ready.
16+
- Running: the job runs one report-generation business function and prints the current UNIX time.
17+
- Completion: the job returns `TaskResult::Succeeded`, matching the job role's one-shot behavior.
18+
- Cleanup: `main.rs` calls `shutdown_tree` after the job has stopped itself.
19+
20+
## File Layout
21+
22+
- `main.rs`: wires the supervisor, event subscription, state snapshots, and cleanup shutdown.
23+
- `job_task.rs`: declares the `WorkRole::Job` child and the one-shot job body.
24+
- `observation.rs`: prints job facts, runtime events, current state records, and shutdown outcomes.

examples/job/README.zh.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Job(一次性任务) 角色示例
2+
3+
[English README](README.md)
4+
5+
这个示例展示一个一次性 `WorkRole::Job`(工作角色: 一次性任务) 子任务. Job(一次性任务) 角色适合有限工作, 工作完成后应该停止.
6+
7+
运行命令:
8+
9+
```bash
10+
cargo run --package rust-tokio-supervisor --example job
11+
```
12+
13+
## 示例展示内容
14+
15+
- 初始化: `job_task.rs` 构建 `daily-report-job` 子任务, 并报告 readiness(就绪状态).
16+
- 运行: job(一次性任务) 执行一次 report generation(报告生成) 业务函数, 并输出当前 UNIX time(UNIX 时间).
17+
- 完成: job(一次性任务) 返回 `TaskResult::Succeeded`(任务成功), 对齐 job(一次性任务) 一次性运行的角色语义.
18+
- 清理: job(一次性任务) 自己停止后, `main.rs` 调用 `shutdown_tree`(关闭监督树) 清理 runtime(运行时).
19+
20+
## 文件结构
21+
22+
- `main.rs`: 组合 supervisor(监督器), event subscription(事件订阅), state snapshot(状态快照) 和 cleanup shutdown(清理关闭).
23+
- `job_task.rs`: 声明 `WorkRole::Job`(工作角色: 一次性任务) 子任务, 并实现 one-shot job body(一次性任务主体).
24+
- `observation.rs`: 输出 job fact(一次性任务事实), runtime event(运行时事件), current state record(当前状态记录) 和 shutdown outcome(关闭结果).

0 commit comments

Comments
 (0)