Skip to content

feat!: domain-centric API with typed event streams#48

Merged
deepjoy merged 4 commits into
mainfrom
typesafe-api
Mar 18, 2026
Merged

feat!: domain-centric API with typed event streams#48
deepjoy merged 4 commits into
mainfrom
typesafe-api

Conversation

@deepjoy

@deepjoy deepjoy commented Mar 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • Introduce DomainKey, Domain<D>, DomainHandle<D>, and TypedExecutor<T> — a compile-time–enforced replacement for the stringly-typed Module/ModuleHandle API
  • Add TypedTask::type Domain associated type so the compiler validates that each task is registered in the correct domain
  • Replace per-method TypedTask defaults with a single fn config() -> TaskTypeConfig that covers priority, IO budget, TTL, retry policy, dedup strategy, and scheduling
  • Add TypedEventStream<T> and TaskEvent<T> for per-task-type typed event subscriptions with terminal variants that carry an Arc<TaskHistoryRecord>
  • Add ctx.domain::<D>() for cross-domain task submission from within executors, replacing the now-internal ctx.module("name")
  • Rewrite all documentation (quick-start, guides, configuration, multi-module, query APIs, etc.) for the new API
  • Add docs/migrating-to-0.5.md covering all seven breaking change areas with before/after examples
  • Fix CI benchmark workflow: pre-build with --no-run to keep compilation noise out of bench-output.txt

Breaking changes

  • Module and ModuleHandle are removed from the public API; replace with Domain<D> and DomainHandle<D>
  • TypedTask impls must add type Domain = YourDomainKey;
  • impl TaskExecutor executors must be rewritten as impl TypedExecutor<T> (payload arrives deserialized)
  • SchedulerBuilder::module() is now private; use SchedulerBuilder::domain()
  • scheduler.module("name") is now private; use scheduler.domain::<D>()
  • See docs/migrating-to-0.5.md for the full checklist

deepjoy added 4 commits March 18, 2026 04:33
Replace the stringly-typed Module/ModuleHandle API with a compile-time
type-safe Domain model. This is a breaking change — no backward
compatibility is maintained.

New types:
- DomainKey: marker trait for compile-time module identity
- TaskTypeConfig: static per-task-type defaults (priority, IO, TTL, retry)
- TypedExecutor<T>: executor receiving deserialized typed payloads
- Domain<D>: typed module builder replacing Module
- DomainHandle<D>: typed module handle replacing ModuleHandle
- DomainSubmitBuilder<D>: typed per-call override builder

Updated traits:
- TypedTask: added `type Domain: DomainKey` and `fn config() -> TaskTypeConfig`,
  removed 9 instance methods (priority, expected_io, group_key, etc.)
- RetryPolicy: added convenience constructors (constant, linear,
  exponential, exponential_jitter)

Removed from public API:
- Module, ModuleRegistry, ModuleSubmitDefaults, SubmitBuilder
- Scheduler::module(), Scheduler::modules()
- SchedulerBuilder::module()
- TypedTask instance methods replaced by config()

Retained as Phase 1 bridge (until Phase 2 adds ctx.domain::<D>()):
- TaskContext::current_module() and ModuleHandle for cross-module
  submission from within executors

All tests (267), benchmarks, and clippy pass with zero warnings.
Add TaskEvent<T>, TypedEventStream<T>, DomainHandle::task_events::<T>(),
ctx.domain::<D>(), ctx.try_domain::<D>(), and ctx.domain_state::<D, S>().
Remove TaskContext::current_module() and ModuleHandle from the public API.
Terminal event variants include Arc<TaskHistoryRecord> for zero-roundtrip
payload access. Remove unused ModuleHandle methods (prefix, task,
count_by_tag, tag_values).
Update lib.rs module-level docs, README quickstart, and all doc guides
to use the new Domain/DomainHandle/TypedExecutor API introduced in
Phases 1-2. Replace all Module/ModuleHandle/TaskExecutor examples with
their domain-centric equivalents. Fix rustdoc warnings for stale
TypedTask::priority() links and private Module references.
Compilation noise (crate downloads, rustc output) was mixing into
bench-output.txt via 2>&1, leaving no parseable bencher lines for
github-action-benchmark. Split into a build step (--no-run) and a
separate run step so bench-output.txt contains only criterion's
bencher-format stdout.
@deepjoy deepjoy enabled auto-merge (squash) March 18, 2026 12:52
@deepjoy deepjoy merged commit fc1c748 into main Mar 18, 2026
2 checks passed
@github-actions github-actions Bot mentioned this pull request Mar 18, 2026
deepjoy pushed a commit that referenced this pull request Mar 18, 2026
## 🤖 New release

* `taskmill`: 0.4.0 -> 0.5.0 (⚠ API breaking changes)

### ⚠ `taskmill` breaking changes

```text
--- failure inherent_method_missing: pub method removed or renamed ---

Description:
A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/inherent_method_missing.ron

Failed in:
  TaskContext::current_module, previously in file /tmp/.tmpIFcAXT/taskmill/src/registry/context.rs:196
  TaskContext::module, previously in file /tmp/.tmpIFcAXT/taskmill/src/registry/context.rs:211
  TaskContext::try_module, previously in file /tmp/.tmpIFcAXT/taskmill/src/registry/context.rs:218
  TaskContext::current_module, previously in file /tmp/.tmpIFcAXT/taskmill/src/registry/context.rs:196
  TaskContext::module, previously in file /tmp/.tmpIFcAXT/taskmill/src/registry/context.rs:211
  TaskContext::try_module, previously in file /tmp/.tmpIFcAXT/taskmill/src/registry/context.rs:218
  SchedulerBuilder::module, previously in file /tmp/.tmpIFcAXT/taskmill/src/scheduler/builder.rs:102
  SchedulerBuilder::module, previously in file /tmp/.tmpIFcAXT/taskmill/src/scheduler/builder.rs:102
  Scheduler::module, previously in file /tmp/.tmpIFcAXT/taskmill/src/scheduler/mod.rs:270
  Scheduler::try_module, previously in file /tmp/.tmpIFcAXT/taskmill/src/scheduler/mod.rs:276
  Scheduler::modules, previously in file /tmp/.tmpIFcAXT/taskmill/src/scheduler/mod.rs:286
  Scheduler::module, previously in file /tmp/.tmpIFcAXT/taskmill/src/scheduler/mod.rs:270
  Scheduler::try_module, previously in file /tmp/.tmpIFcAXT/taskmill/src/scheduler/mod.rs:276
  Scheduler::modules, previously in file /tmp/.tmpIFcAXT/taskmill/src/scheduler/mod.rs:286

--- failure module_missing: pub module removed or renamed ---

Description:
A publicly-visible module cannot be imported by its prior path. A `pub use` may have been removed, or the module may have been renamed, removed, or made non-public.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/module_missing.ron

Failed in:
  mod taskmill::module, previously in file /tmp/.tmpIFcAXT/taskmill/src/module.rs:1

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/struct_missing.ron

Failed in:
  struct taskmill::module::ModuleHandle, previously in file /tmp/.tmpIFcAXT/taskmill/src/module.rs:396
  struct taskmill::ModuleHandle, previously in file /tmp/.tmpIFcAXT/taskmill/src/module.rs:396
  struct taskmill::module::ModuleReceiver, previously in file /tmp/.tmpIFcAXT/taskmill/src/module.rs:336
  struct taskmill::ModuleReceiver, previously in file /tmp/.tmpIFcAXT/taskmill/src/module.rs:336
  struct taskmill::module::ModuleSnapshot, previously in file /tmp/.tmpIFcAXT/taskmill/src/module.rs:313
  struct taskmill::ModuleSnapshot, previously in file /tmp/.tmpIFcAXT/taskmill/src/module.rs:313
  struct taskmill::module::ModuleEntry, previously in file /tmp/.tmpIFcAXT/taskmill/src/module.rs:264
  struct taskmill::SubmitBuilder, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/submit_builder.rs:81
  struct taskmill::module::Module, previously in file /tmp/.tmpIFcAXT/taskmill/src/module.rs:79
  struct taskmill::Module, previously in file /tmp/.tmpIFcAXT/taskmill/src/module.rs:79
  struct taskmill::module::ExecutorOptions, previously in file /tmp/.tmpIFcAXT/taskmill/src/module.rs:28
  struct taskmill::module::ModuleRegistry, previously in file /tmp/.tmpIFcAXT/taskmill/src/module.rs:282
  struct taskmill::ModuleRegistry, previously in file /tmp/.tmpIFcAXT/taskmill/src/module.rs:282
  struct taskmill::ModuleSubmitDefaults, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/submit_builder.rs:42

--- failure trait_associated_type_added: non-sealed public trait added associated type without default value ---

Description:
A non-sealed trait has gained an associated type without a default value, which breaks downstream implementations of the trait
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-item-no-default
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/trait_associated_type_added.ron

Failed in:
  trait associated type taskmill::task::typed::TypedTask::Domain in file /tmp/.tmpUI6vfZ/taskmill/src/task/typed.rs:58
  trait associated type taskmill::task::TypedTask::Domain in file /tmp/.tmpUI6vfZ/taskmill/src/task/typed.rs:58
  trait associated type taskmill::TypedTask::Domain in file /tmp/.tmpUI6vfZ/taskmill/src/task/typed.rs:58

--- failure trait_method_missing: pub trait method removed or renamed ---

Description:
A trait method is no longer callable, and may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#major-any-change-to-trait-item-signatures
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/trait_method_missing.ron

Failed in:
  method expected_io of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:47
  method priority of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:52
  method group_key of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:67
  method on_duplicate of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:72
  method ttl of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:77
  method ttl_from of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:82
  method run_after of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:87
  method recurring of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:92
  method expected_io of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:47
  method priority of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:52
  method group_key of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:67
  method on_duplicate of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:72
  method ttl of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:77
  method ttl_from of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:82
  method run_after of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:87
  method recurring of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:92
  method expected_io of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:47
  method priority of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:52
  method group_key of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:67
  method on_duplicate of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:72
  method ttl of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:77
  method ttl_from of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:82
  method run_after of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:87
  method recurring of trait TypedTask, previously in file /tmp/.tmpIFcAXT/taskmill/src/task/typed.rs:92
```

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.5.0](v0.4.0...v0.5.0)
- 2026-03-18

### Added

- [**breaking**] domain-centric API with typed event streams
([#48](#48))

### Fixed

- *(ci)* capture benchmark output from stderr in workflow
([#47](#47))

### Other

- add multi-module guides, benchmarks, and CI benchmark workflow
([#45](#45))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
deepjoy added a commit that referenced this pull request Mar 18, 2026
PR #48 accidentally reverted the `2>&1` fix from PR #47. Criterion writes
bencher-format output to stderr, so `2>/dev/null` was silently discarding it,
leaving bench-output.txt empty on push-to-main runs.

The github-action-benchmark step only runs on push events, so PR runs
never exercised the broken path — the failure only surfaced after merge.
deepjoy added a commit that referenced this pull request Mar 18, 2026
PR #48 accidentally reverted the `2>&1` fix from PR #47. Criterion
writes bencher-format output to stderr, so `2>/dev/null` was silently
discarding it, leaving bench-output.txt empty on push-to-main runs.

The github-action-benchmark step only runs on push events, so PR runs
never exercised the broken path — the failure only surfaced after merge.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant