Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Retire the queued runs of an event a newer one replaced

8ca8bbe04848a350f514eb956f70951b701bcd9c · Keenan Nemetz · 10d ago · parent 3031e357

Retire the queued runs of an event a newer one replaced

Opening a change request and then updating it queued two full sets of the
workflow's jobs for the same base commit. Neither superseded the other: the
occurrence is what makes event runs distinct, and CancelSuperseded only looks
at pushes. On a single-slot runner the newer event waited behind the older
event's identical work, and every edit added another set.

A run now records the subject of the event that queued it: a change-request
ID, an issue ID, or an entity and comment pair. When an event's batch is
queued, the queued runs of an older event for the same repository, trigger,
and subject are canceled. The batch's own occurrences are kept, so an edited
and an assigned action from one push do not cancel each other. Only queued
rows are touched: a handler that has started finishes, because it is already
acting on the event it received. Schedules and dispatches have no subject and
are unchanged.

The query needs no ref: the subject is a globally unique entity ID, so a base
branch that moved does not keep the older set alive, and another change
request's queue on the same branch is untouched.

Verified with go test ./server/, the store tests, and vole workflow run verify.

server/ci.go +24−4

@@ -145,9 +145,15 @@ type queueSpec struct {
145 145 // event carries the filters a non-push trigger is evaluated against. Kind and
146 146 // Action are filled from trigger and action in queue, so a caller only supplies
147 147 // what the event payload says about its body, sender and assignees.
148 event ci.EventContext
149 payload string
150 occurrence string
148 event ci.EventContext
149 payload string
150 occurrence string
151 // subject is the entity whose event queued these runs: a change request, an
152 // issue, or one comment. Empty for a push, schedule, or manual dispatch. batch
153 // lists every occurrence this event queues, so its own actions do not supersede
154 // each other while an older event for the same subject is retired.
155 subject string
156 batch []string
151 157 changed []string
152 158 cancelSuperseded bool
153 159 }
@@ -227,6 +233,7 @@ func (s *Server) queue(m *repo.Meta, repoName string, spec queueSpec) int {
227 233 TriggerAction: spec.action,
228 234 EventPayload: spec.payload,
229 235 Occurrence: spec.occurrence,
236 Subject: spec.subject,
230 237 Job: job.ID,
231 238 JobName: job.Name,
232 239 JobDescription: job.Description,
@@ -253,12 +260,25 @@ func (s *Server) queue(m *repo.Meta, repoName string, spec queueSpec) int {
253 260 if len(owing) == 0 {
254 261 return 0
255 262 }
263 // An event supersedes by subject rather than by ref: a newer change, issue, or
264 // comment event retires the queued runs of the event it replaced, while another
265 // change request's queue on the same base branch is untouched. Only queued rows are
266 // canceled; a handler that has started finishes.
267 if spec.subject != "" {
268 if n, err := s.Runs.CancelSupersededEvents(repoName, spec.trigger, spec.subject, spec.batch, time.Now().UTC()); err != nil {
269 s.Log.Warn("ci: cannot cancel superseded event runs", "repo", repoName,
270 "trigger", spec.trigger, "subject", spec.subject, "err", err)
271 } else if n > 0 {
272 s.Log.Info("ci: canceled superseded event runs", "repo", repoName,
273 "trigger", spec.trigger, "subject", spec.subject, "runs", n)
274 }
275 }
256 276 // A newer tip supersedes the runs of the older one: pushing twice in a minute must
257 277 // not build the first commit twice. A queued job is canceled; a running one is
258 278 // asked to stop, because the commit it is building is no longer what the ref means.
259 279 // The cancellation is logged because a run that stopped for a reason nobody can
260 280 // find is the same as a run that vanished. A candidate ref names one commit, so
261 // this is a no-op for combined results; a metadata event never cancels anything.
281 // this is a no-op for combined results.
262 282 if spec.cancelSuperseded {
263 283 if n, err := s.Runs.CancelSuperseded(repoName, spec.ref, spec.commit, time.Now().UTC()); err != nil {
264 284 s.Log.Warn("ci: cannot cancel superseded runs", "repo", repoName, "ref", spec.ref, "err", err)