Documentation
¶
Overview ¶
Package taskreg 提供 Worker 侧「运行中长任务内存登记表」(FR-183,见 ADR-040)。
长任务(如 JDK 安装)启动即返回 task_id 后,后台 goroutine 经本登记表持续更新进度/日志; 心跳每周期把表内任务快照随心跳上报给 CP。任务进入终态(succeeded/failed)并被心跳上报后 由心跳侧调用 Drop 从表内移除(已落 CP,无需再报)。
多协程安全:后台执行 goroutine 写、心跳 goroutine 读,全程加锁。
Index ¶
- type Registry
- func (r *Registry) AppendLog(taskID, line string)
- func (r *Registry) Cancel(taskID string) bool
- func (r *Registry) Drop(taskID string)
- func (r *Registry) Fail(taskID, errMsg string)
- func (r *Registry) SetProgress(taskID string, progress int32)
- func (r *Registry) Snapshot() []*workerpb.TaskSnapshot
- func (r *Registry) Start(taskID string, cancel context.CancelFunc)
- func (r *Registry) Succeed(taskID, result string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry 运行中任务的线程安全登记表。零值不可用,须经 New 创建。
func (*Registry) Cancel ¶
Cancel 强制停止任务(FR-227):调用其执行 context 的 cancel(真中断下载等操作)并置 canceled 终态。 仅对运行中任务生效(已终态/不存在返回 false,幂等——心跳可能重复下发同一 id)。
func (*Registry) SetProgress ¶
SetProgress 更新任务进度(0~100)。任务不存在则忽略。
func (*Registry) Snapshot ¶
func (r *Registry) Snapshot() []*workerpb.TaskSnapshot
Snapshot 返回当前所有任务的快照(用于心跳上报)。返回的切片与底层状态解耦,可安全跨协程使用。
Click to show internal directories.
Click to hide internal directories.