feat!: support passing state from execute() to finalize() via typed Memo#69
Merged
Conversation
Add a default type parameter `Memo = ()` to `TypedExecutor<T>` that lets executors return typed state from `execute()` which is persisted to SQLite and delivered to `finalize()` after children complete. - Add `memo BLOB` column to `tasks` and `task_history` (migration 009) - `TypedExecutor::execute()` returns `Result<Memo, TaskError>` - `TypedExecutor::finalize()` receives the `Memo` as a parameter - Memo is serialized at `set_waiting` (the single correct write point) - `TypeId::of::<()>()` check avoids DB writes for non-memo tasks - `Domain::task::<T>()` unchanged; new `Domain::task_memo()` for memo executors - Existing executors with `Memo = ()` require zero code changes - Executors overriding `finalize()` add `_memo: ()` parameter BREAKING CHANGE: `TypedExecutor::finalize()` signature adds a `Memo` parameter between `payload` and `ctx`.
Contributor
Benchmark ComparisonClick to expand |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Memo = ()toTypedExecutor<T>so executors can return typed state fromexecute()that is persisted to SQLite and delivered tofinalize()after children completeDomain::task_memo()andDomain::task_with_memo()registration methods for memo-producing executors; existingDomain::task()is unchangedmemo BLOBcolumn totasksandtask_historytables (migration 009);TypeId::of::<()>()check avoids DB writes for non-memo taskslib.rs,quick-start.md,migrating-to-0.5.md) to include the new_memo: ()parameter infinalize()signaturesCloses #64
Details
The memo is serialized via
serde_jsonat theset_waitingtransition (the single correct write point after execute returns and children are detected). On finalize dispatch, the memo bytes are deserialized back into the concreteMemotype. WhenMemo = (), no serialization or DB write occurs — theTypeIdguard short-circuits toOk(None).Public API changes
TypedExecutor<T>TypedExecutor<T, Memo = ()>execute() -> Result<(), TaskError>execute() -> Result<Memo, TaskError>finalize(payload, ctx)finalize(payload, memo, ctx)Domain::task()Domain::task()(unchanged) +Domain::task_memo()Domain::task_with()Domain::task_with()(unchanged) +Domain::task_with_memo()Migration
Existing executors with
Memo = ()only need to add_memo: ()to theirfinalize()override (if any). Executors that don't overridefinalize()require zero changes.BREAKING CHANGE
TypedExecutor::finalize()signature adds aMemoparameter betweenpayloadandctx.