You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
developerworks
committed
Fix yaml service example event handling and document ChildSpec paths
- Fix yaml service example: skip first interval tick to delay first output by one second
- Switch from batched polling to immediate event receive in yaml service example
- Add ChildSpec construction paths comparison table to the manual (EN/ZH)
- Fix brainstorming session frontmatter formatting and table alignment
Copy file name to clipboardExpand all lines: rust-supervisor/manual/en/child-spec.md
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,6 +56,36 @@ When a child is added dynamically, `PendingChild` keeps **both** the `declaratio
56
56
57
57
Shared enums and config structs such as `RestartPolicy`, `TaskKind`, and `HealthCheckConfig` are defined in `child.rs`. `ChildDeclaration`**reuses** them to avoid parallel type trees. The **top-level containers** remain separate: declaration container vs specification container.
58
58
59
+
## ChildSpec construction paths
60
+
61
+
The repository has 6 paths that construct `ChildSpec`. They serve different use cases and should not be collapsed into one entry point.
62
+
63
+
| Path | Typical entry | Use case | Validation behavior |
64
+
| --- | --- | --- | --- |
65
+
| Builder |`ChildSpecBuilder::worker`, `service`, `job`, `sidecar`, `supervisor`, `new`| Direct runtime spec construction in Rust code |`build()` calls `ChildSpec::validate()`|
66
+
| Worker convenience function |`ChildSpec::worker(...)`| Worker default bundle only | Delegates to `ChildSpecBuilder::worker(...).build()`|
67
+
| Declaration conversion |`TryFrom<ChildDeclaration> for ChildSpec`| YAML config, RPC payloads, dynamic child adds |`validate_child_declaration` runs before conversion, and supervisor-level validation catches final issues |
68
+
| Role template |`ServiceTemplate::child_spec`, `JobTemplate::child_spec`, and related role templates | Caller already implemented role traits but does not want to hand-build adapters and specs | Calls the matching `ChildSpecBuilder` internally |
69
+
| Macro-generated helper |`child_spec()` generated by `#[service]`, `#[worker]`, `#[job]`, `#[sidecar]`, and `#[supervisor_role]`| Default role contract entry path | Generated code calls the matching `ChildSpecBuilder`|
70
+
| Serde |`serde_json::from_value::<ChildSpec>(...)`| Mainly tests for deserialization defaults and invalid enum handling | Does not pass through the builder, so callers must validate before runtime use or rely on later spec validation |
71
+
72
+
Important boundaries:
73
+
74
+
-`ChildSpecBuilder::build()` is the main exit for Rust code construction paths.
75
+
- Configuration and RPC should not accept `ChildSpec` directly. They should accept `ChildDeclaration` first, then convert it into `ChildSpec`.
76
+
- Role templates and macros are not new runtime models. They turn role lifecycle objects into adapters, then call `ChildSpecBuilder` to produce specs.
77
+
- Serde can construct `ChildSpec` because `ChildSpec` derives `Deserialize`. That path does not automatically call `ChildSpecBuilder::build()`.
78
+
79
+
Adjacent paths that do not construct a `ChildSpec`:
80
+
81
+
| Entry | Why it is not a `ChildSpec` construction path |
82
+
| --- | --- |
83
+
|`SupervisorSpec::root(Vec<ChildSpec>)`| It accepts already constructed child specs and builds a supervisor spec |
84
+
|`SupervisorSpecBuilder::root(Vec<ChildSpec>)`| It wraps supervisor spec construction and does not create an individual child spec |
85
+
|`ConfigState::to_supervisor_spec()`| It assembles a supervisor spec from the `Vec<ChildSpec>` already stored in `ConfigState`|
86
+
|`bind_child_factory(...)`| It binds a task factory to an existing `ChildSpec` and does not create a new one |
87
+
|`clone()`| It copies an existing `ChildSpec` instead of generating one from an input model |
0 commit comments