taskflow: run extensions through one dispatcher and tell them which phase they run in

未关闭
#396 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@mushrafmim 已经在做这个了。

开始于 2026年11月9日。

  • #397 来自 @mushrafmim —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
22/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
停滞
技术栈
go
领域
backend

调研方向

Start with the two call sites that run extensions, CompleteTaskStep and SaveDraft, and the stopOnError and go func() logic they each duplicate. The issue asks for an extensions.Invocation context value, an orchestrator.Dispatcher with WithDispatcher, and an internal fire that handles guard and notify phases. Work is already under way in open PR #397, so coordinate there before starting. Done means both existing phases behave as before and POST_RESUME goes through the dispatcher.

由索引模型根据 Issue 内容生成。

描述

Type/Improvement
Current Limitation

The orchestrator runs extensions from two call sites, CompleteTaskStep and SaveDraft. Each call site deep-copies the record and payload itself, and each decides for itself whether the run blocks or is asynchronous, using a stopOnError bool and a hand-written go func(). Adding the lifecycle phases in #395 this way would copy that logic into every new call site.

It also leaves two gaps:

  • An extension can't tell which phase it is running in, or recognise a repeat of an event it already handled.
  • POST_RESUME always runs in a bare goroutine. A host can't bound its concurrency, recover its panics, or run it inline in tests, which currently need a WaitGroup to wait for it.
Suggested Improvement

Route every extension run through one dispatcher, with no behaviour change for the two existing phases:

  • extensions.Invocation{Phase, IdempotencyKey} on the context passed to Execute, read with extensions.InvocationFrom(ctx). The key is <task id>/<step id>/<seq>/<phase> and names the run of the step, whatever seq the row has moved on to. TaskExtension is unchanged.
  • orchestrator.Dispatcher (with a DispatcherFunc adapter) runs notify phases, set with WithDispatcher. The default is one goroutine per dispatch, as today.
  • An internal fire(phase, …) looks up the phase's policy. A guard (PRE_RESUME) runs inline and returns the first error. A notify (POST_RESUME) is handed to the dispatcher with a context that is never cancelled. Deep copies are made in one place.
Version

53b0bd3

Additional Context

This is PR 1 of the rollout in #395. Telling a draft save apart from a submission (#327) stays separate.

主要语言
Go
星标
6
派生
8
平均合并
21 小时 36 分钟
30 天内合并 PR
42

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

OpenNSW/core 的其他 Issue

查看 OpenNSW/core 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。