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/events.go +22−12
| @@ -334,10 +334,7 @@ func (s *Server) issueEvent(m *repo.Meta, old string, c git.Commit, acl *access. | |||
| 334 | 334 | URL: "/" + m.Name + "/issues/" + newIssue.ID, | |
| 335 | 335 | }, | |
| 336 | 336 | } | |
| 337 | for _, action := range actions { | ||
| 338 | s.queuePayload(m, "issue", action, ref, branch, "", commit, acl, payload, | ||
| 339 | c.SHA+":issue:"+action+":"+issueID) | ||
| 340 | } | ||
| 337 | s.queueEvent(m, "issue", issueID, ref, branch, "", commit, acl, payload, c.SHA, actions) | ||
| 341 | 338 | } | |
| 342 | 339 | ||
| 343 | 340 | // nameDiff reports which names were added to and removed from a set. Both lists | |
| @@ -428,8 +425,10 @@ func (s *Server) commentEvent(m *repo.Meta, old string, c git.Commit, acl *acces | |||
| 428 | 425 | ReplyTo: shown.ReplyTo, ReplyToAuthor: replyToAuthor, Deleted: shown.Deleted, | |
| 429 | 426 | URL: url + "#c-" + shown.ID}, | |
| 430 | 427 | } | |
| 431 | s.queuePayload(m, "comment", action, ref, branch, "", commit, acl, payload, | ||
| 432 | c.SHA+":comment:"+action+":"+entityID+":"+commentID) | ||
| 428 | // A comment is its own subject, so editing or deleting one supersedes that comment's | ||
| 429 | // queued event without touching a reply to another comment. | ||
| 430 | s.queueEvent(m, "comment", entityID+":"+commentID, ref, branch, "", commit, acl, payload, | ||
| 431 | c.SHA, []string{action}) | ||
| 433 | 432 | } | |
| 434 | 433 | ||
| 435 | 434 | func findComment(m *repo.Meta, commit, entityID, commentID string, request bool) *metadata.Comment { | |
| @@ -517,10 +516,8 @@ func (s *Server) changeRequestEvent(m *repo.Meta, old string, c git.Commit, acl | |||
| 517 | 516 | actions = append(actions, "ready") | |
| 518 | 517 | } | |
| 519 | 518 | } | |
| 520 | for _, action := range actions { | ||
| 521 | s.queuePayload(m, "change_request", action, baseRef, newReq.Base, "", base, acl, payload, | ||
| 522 | c.SHA+":change_request:"+action+":"+requestID) | ||
| 523 | } | ||
| 519 | s.queueEvent(m, "change_request", requestID, baseRef, newReq.Base, "", base, acl, payload, | ||
| 520 | c.SHA, actions) | ||
| 524 | 521 | } | |
| 525 | 522 | ||
| 526 | 523 | func (s *Server) defaultBranchCommit(m *repo.Meta) (ref, branch, commit string, err error) { | |
| @@ -539,7 +536,20 @@ func (s *Server) defaultBranchCommit(m *repo.Meta) (ref, branch, commit string, | |||
| 539 | 536 | return ref, branch, commit, nil | |
| 540 | 537 | } | |
| 541 | 538 | ||
| 542 | func (s *Server) queuePayload(m *repo.Meta, trigger, action, ref, branch, tag, commit string, acl *access.ACL, payload eventPayload, occurrence string) { | ||
| 539 | // queueEvent queues the runs for one repository event. Every action in the batch | ||
| 540 | // shares the event's subject and sees the whole batch, so the actions of one event do | ||
| 541 | // not supersede each other while an older event for the same subject is retired. | ||
| 542 | func (s *Server) queueEvent(m *repo.Meta, trigger, subject, ref, branch, tag, commit string, acl *access.ACL, payload eventPayload, metaCommit string, actions []string) { | ||
| 543 | batch := make([]string, len(actions)) | ||
| 544 | for i, action := range actions { | ||
| 545 | batch[i] = metaCommit + ":" + trigger + ":" + action + ":" + subject | ||
| 546 | } | ||
| 547 | for i, action := range actions { | ||
| 548 | s.queuePayload(m, trigger, action, ref, branch, tag, commit, acl, payload, batch[i], subject, batch) | ||
| 549 | } | ||
| 550 | } | ||
| 551 | |||
| 552 | func (s *Server) queuePayload(m *repo.Meta, trigger, action, ref, branch, tag, commit string, acl *access.ACL, payload eventPayload, occurrence, subject string, batch []string) { | ||
| 543 | 553 | payload.Event = trigger | |
| 544 | 554 | payload.Action = action | |
| 545 | 555 | body, err := json.Marshal(payload) | |
| @@ -556,7 +566,7 @@ func (s *Server) queuePayload(m *repo.Meta, trigger, action, ref, branch, tag, c | |||
| 556 | 566 | n := s.queue(m, m.Name, queueSpec{ | |
| 557 | 567 | ref: ref, branch: branch, tag: tag, commit: commit, | |
| 558 | 568 | trigger: trigger, action: action, event: event, | |
| 559 | payload: string(body), occurrence: occurrence, | ||
| 569 | payload: string(body), occurrence: occurrence, subject: subject, batch: batch, | ||
| 560 | 570 | }) | |
| 561 | 571 | if n > 0 { | |
| 562 | 572 | s.Log.Info("ci: queued an event run", "repo", m.Name, "trigger", trigger, "action", action, "runs", n) | |