Documentation
¶
Overview ¶
Package progress 提供多阶段工作流的进度追踪模型。
Tracker 支持有序阶段的生命周期管理(pending → active → completed), 自动完成前置阶段,线程安全。适用于构建流水线、数据处理、代码审查等多步骤任务。
用法:
t := progress.NewTracker([]progress.PhaseConfig{
{Name: "init", Title: "Initialization"},
{Name: "process", Title: "Processing"},
{Name: "finish", Title: "Finalization"},
})
t.UpdatePhase("init", progress.PhaseActive, 0)
t.UpdatePhase("init", progress.PhaseCompleted, 100)
fmt.Println(t.GetOverallProgress()) // 33.33
Package progress 提供多阶段工作流的进度追踪模型。 适用于代码审查、构建流水线、数据处理等多步骤任务的进度管理。
Index ¶
- type PhaseConfig
- type PhaseInfo
- type PhaseStatus
- type TaskStatus
- type Tracker
- func (t *Tracker) Complete()
- func (t *Tracker) Fail()
- func (t *Tracker) GetDuration() time.Duration
- func (t *Tracker) GetOverallProgress() float64
- func (t *Tracker) GetPhase(name string) (PhaseInfo, bool)
- func (t *Tracker) GetPhases() []PhaseInfo
- func (t *Tracker) GetStatus() TaskStatus
- func (t *Tracker) IsCompleted() bool
- func (t *Tracker) UpdatePhase(name string, status PhaseStatus, progress float64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PhaseConfig ¶
PhaseConfig 定义一个阶段的配置。
type PhaseInfo ¶
type PhaseInfo struct {
Name string `json:"name"`
Title string `json:"title"`
Description string `json:"description"`
Status PhaseStatus `json:"status"`
Progress float64 `json:"progress"`
StartTime time.Time `json:"start_time,omitempty"`
EndTime time.Time `json:"end_time,omitempty"`
Duration int64 `json:"duration_ms,omitempty"`
}
PhaseInfo 表示单个阶段的运行时信息。
type PhaseStatus ¶
type PhaseStatus string
PhaseStatus 表示阶段的状态。
const ( PhasePending PhaseStatus = "pending" PhaseActive PhaseStatus = "active" PhaseCompleted PhaseStatus = "completed" PhaseFailed PhaseStatus = "failed" PhaseSkipped PhaseStatus = "skipped" )
type TaskStatus ¶
type TaskStatus string
TaskStatus 表示整个追踪任务的状态。
const ( // TaskRunning 任务进行中。 TaskRunning TaskStatus = "running" // TaskCompleted 任务已成功完成。 TaskCompleted TaskStatus = "completed" // TaskFailed 任务失败。 TaskFailed TaskStatus = "failed" )
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker 是多阶段进度追踪器。 线程安全,支持并发更新。
用法:
t := progress.NewTracker([]progress.PhaseConfig{
{Name: "init", Title: "Initialization"},
{Name: "process", Title: "Processing"},
{Name: "finish", Title: "Finalization"},
})
t.UpdatePhase("init", progress.PhaseActive, 0)
t.UpdatePhase("init", progress.PhaseCompleted, 100)
func NewTracker ¶
func NewTracker(phases []PhaseConfig) *Tracker
NewTracker 创建进度追踪器。phases 按顺序定义所有阶段。
func (*Tracker) GetDuration ¶
GetDuration 返回追踪器运行的总时长。
func (*Tracker) GetOverallProgress ¶
GetOverallProgress 计算所有阶段的平均进度。
func (*Tracker) UpdatePhase ¶
func (t *Tracker) UpdatePhase(name string, status PhaseStatus, progress float64)
UpdatePhase 更新指定阶段的状态和进度。 自动完成该阶段之前的所有阶段。
Click to show internal directories.
Click to hide internal directories.