fix: commit run notification intents with state transitions
This commit is contained in:
@@ -35,6 +35,23 @@ func (r *runner) notifyStep(id int64, name, workspace string, policy *protocol.N
|
||||
if !enabled {
|
||||
return
|
||||
}
|
||||
var lease *pipeline.RunNotification
|
||||
runEvent := stageAttentionEvent(event)
|
||||
if event == "success" && step.Target == protocol.SuccessEnd {
|
||||
runEvent = "succeeded"
|
||||
}
|
||||
if event == protocol.NotifyWaiting || step.Target == protocol.SuccessEnd || step.Target == protocol.FailureEnd {
|
||||
var allowed bool
|
||||
var err error
|
||||
lease, allowed, err = r.store.ClaimStageRunNotification(r.ctx, id, step.Sequence, runEvent, time.Now().Unix())
|
||||
if err != nil {
|
||||
log.Printf("claim stage notification run=%d: %v", id, err)
|
||||
return
|
||||
}
|
||||
if !allowed {
|
||||
return
|
||||
}
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
summary := fmt.Sprintf("%s · run #%d · stage %s · %s (%s)", name, id, step.Stage, event, step.Outcome)
|
||||
@@ -134,7 +151,36 @@ func (r *runner) notifyStep(id int64, name, workspace string, policy *protocol.N
|
||||
covered = "succeeded"
|
||||
}
|
||||
r.markAttentionSent(id, step.Sequence, covered)
|
||||
break
|
||||
return
|
||||
}
|
||||
}
|
||||
if lease != nil {
|
||||
diagnostic := "stage notification publication failed"
|
||||
if len(receipts) > 0 && receipts[0].Diagnostic != "" {
|
||||
diagnostic = receipts[0].Diagnostic
|
||||
}
|
||||
if err := r.store.FinishRunNotification(r.ctx, *lease, time.Now().Unix(), "", fmt.Errorf("%s", diagnostic)); err != nil {
|
||||
log.Printf("release stage notification run=%d: %v", id, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Terminal hooks run only after FinishRun commits. They arbitrate against the
|
||||
// durable intent just like waiting hooks, never publishing a proposed success.
|
||||
func (r *runner) notifyTerminalStep(id int64, status string) {
|
||||
detail, err := r.store.GetRun(r.ctx, id)
|
||||
if err != nil || len(detail.Steps) == 0 {
|
||||
return
|
||||
}
|
||||
step := detail.Steps[len(detail.Steps)-1]
|
||||
stepStatus, _, _, terminal := terminalFinish(step.Target, step.Stage, step.Outcome, step.Diagnostic)
|
||||
if !terminal || stepStatus != status {
|
||||
return
|
||||
}
|
||||
for _, definition := range detail.Graph.Stages {
|
||||
if definition.Key == step.Stage {
|
||||
r.notifyStep(id, detail.Name, detail.Workspace, definition.Notify, step)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user