Report live correction progress through CommandKit
This commit is contained in:
18
internal/framework/runner/progress.go
Normal file
18
internal/framework/runner/progress.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package runner
|
||||
|
||||
// Progress identifies work admitted or completed by the runner.
|
||||
type Progress struct {
|
||||
ModuleIndex int
|
||||
ModuleKey string
|
||||
ModuleID *string
|
||||
SectionIndex *int
|
||||
State string
|
||||
Count *int
|
||||
}
|
||||
|
||||
func (event Progress) emit(callback func(Progress), state string, section *int, count *int) {
|
||||
if callback != nil {
|
||||
event.State, event.SectionIndex, event.Count = state, section, count
|
||||
callback(event)
|
||||
}
|
||||
}
|
||||
@@ -119,6 +119,7 @@ type RunInput struct {
|
||||
ModuleSpecs []contracts.ModuleRunSpec
|
||||
Interactions structuredoutput.InteractionSink
|
||||
Evidence *EvidenceSelection
|
||||
Progress func(Progress)
|
||||
}
|
||||
|
||||
// RunOutput is the deterministic runner output.
|
||||
@@ -175,11 +176,14 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (RunOutput, error) {
|
||||
}
|
||||
|
||||
for moduleIndex, spec := range input.ModuleSpecs {
|
||||
progress := Progress{ModuleIndex: spec.Index, ModuleKey: spec.ModuleKey, ModuleID: spec.ID}
|
||||
sectionCount := len(sections)
|
||||
progress.emit(input.Progress, "started", nil, §ionCount)
|
||||
var reportUnits []WorkUnitOutcome
|
||||
if evidence.reports {
|
||||
reportUnits = workUnits[moduleIndex*len(sections) : (moduleIndex+1)*len(sections)]
|
||||
}
|
||||
execution, err := r.executeModule(ctx, spec, sections, input.Interactions, evidence, reportUnits)
|
||||
execution, err := r.executeModule(ctx, spec, sections, input.Interactions, evidence, reportUnits, input.Progress)
|
||||
units := execution.pipeline.WorkUnits
|
||||
if err == nil {
|
||||
filters := findApplyFiltering(sections, execution.pipeline.Approved, execution.skipped, execution.policy)
|
||||
@@ -252,8 +256,11 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (RunOutput, error) {
|
||||
}
|
||||
results = append(results, result)
|
||||
if err != nil {
|
||||
progress.emit(input.Progress, "failed", nil, nil)
|
||||
return snapshot(), fmt.Errorf("module %q failed: %w", spec.InstanceName, err)
|
||||
}
|
||||
corrections := len(execution.applied)
|
||||
progress.emit(input.Progress, "completed", nil, &corrections)
|
||||
}
|
||||
|
||||
if err := ctx.Err(); err != nil {
|
||||
@@ -271,7 +278,7 @@ type moduleExecution struct {
|
||||
appliedBySection []int
|
||||
}
|
||||
|
||||
func (r *Runner) executeModule(ctx context.Context, spec contracts.ModuleRunSpec, sections []chunking.Section, interactions structuredoutput.InteractionSink, evidence evidenceNeeds, reportUnits []WorkUnitOutcome) (moduleExecution, error) {
|
||||
func (r *Runner) executeModule(ctx context.Context, spec contracts.ModuleRunSpec, sections []chunking.Section, interactions structuredoutput.InteractionSink, evidence evidenceNeeds, reportUnits []WorkUnitOutcome, progress func(Progress)) (moduleExecution, error) {
|
||||
var execution moduleExecution
|
||||
origin := failureReference(spec, nil, "")
|
||||
if err := ctx.Err(); err != nil {
|
||||
@@ -289,6 +296,7 @@ func (r *Runner) executeModule(ctx context.Context, spec contracts.ModuleRunSpec
|
||||
Module: module,
|
||||
Evidence: &evidence,
|
||||
ReportUnits: reportUnits,
|
||||
Progress: progress,
|
||||
Spec: spec,
|
||||
Policy: execution.policy,
|
||||
Sections: sections,
|
||||
@@ -359,6 +367,7 @@ func applyWithinSections(sections []chunking.Section, approved []proposals.Enric
|
||||
}
|
||||
|
||||
type collectSectionProposalsInput struct {
|
||||
Progress func(Progress)
|
||||
Evidence *evidenceNeeds
|
||||
ReportUnits []WorkUnitOutcome
|
||||
Interactions structuredoutput.InteractionSink
|
||||
@@ -421,6 +430,8 @@ func proposeSection(ctx context.Context, input collectSectionProposalsInput, sec
|
||||
if ctx.Err() != nil {
|
||||
return result
|
||||
}
|
||||
progress := Progress{ModuleIndex: input.Spec.Index, ModuleKey: input.Spec.ModuleKey, ModuleID: input.Spec.ID}
|
||||
progress.emit(input.Progress, "started", §ion.Index, nil)
|
||||
meta := contracts.SectionMetadataFromSection(section)
|
||||
proposalResult, err := input.Module.Propose(ctx, contracts.ProposalRequest{
|
||||
ExecutionContext: contracts.ExecutionContext{
|
||||
@@ -615,6 +626,7 @@ func runModulePipeline(ctx context.Context, input collectSectionProposalsInput)
|
||||
}
|
||||
}
|
||||
|
||||
progress := Progress{ModuleIndex: input.Spec.Index, ModuleKey: input.Spec.ModuleKey, ModuleID: input.Spec.ID}
|
||||
nextAdmission, active := 0, 0
|
||||
for {
|
||||
for work := pending[nextSectionToRecord]; work != nil && work.finished; work = pending[nextSectionToRecord] {
|
||||
@@ -672,11 +684,20 @@ func runModulePipeline(ctx context.Context, input collectSectionProposalsInput)
|
||||
}
|
||||
}
|
||||
work.finished = true
|
||||
if result.started {
|
||||
progress.emit(input.Progress, "interrupted", &work.unit.Section.Index, nil)
|
||||
}
|
||||
case validated := <-validationResults:
|
||||
active--
|
||||
work := pending[validated.sectionPos]
|
||||
work.validation = &validated
|
||||
work.finished = true
|
||||
state := "completed"
|
||||
if validated.failure != nil {
|
||||
state = "interrupted"
|
||||
}
|
||||
proposals := len(work.candidates)
|
||||
progress.emit(input.Progress, state, &work.unit.Section.Index, &proposals)
|
||||
}
|
||||
}
|
||||
workers.Wait()
|
||||
|
||||
Reference in New Issue
Block a user