issue 974: the checks are queued by pull request on two work-queue streams, taken after a delivery build, dropped when judged, stopped when their key moves; the reordering and the forge-asking end are gone
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package link
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"github.com/novox/mesh-controller/internal/broker"
|
||||
)
|
||||
|
||||
// The kinds of ask, as the queue says them. **The kind decides the queue** (novox/hq ADR 0406 §3): a delivery build is on
|
||||
// the seat's own queue, taken before any check; a check of a pull request marked ready is on the second; every other
|
||||
// check on the third. Nothing orders the asks any more: a builder takes from the queues in that order, and the check
|
||||
// queues keep one request a pull request. The reordering of one queue by moving asks to its tail, with its pause of the
|
||||
// worker, its look every two seconds and its second copies, is gone (issue 558 is answered by the streams).
|
||||
const (
|
||||
KindDelivery = "delivery"
|
||||
KindCheck = "check"
|
||||
)
|
||||
|
||||
// KindOf is an ask's kind: a check for a pull request's check — a recheck the merge tool asks included —
|
||||
// a dry run, or an ask nothing could be read from; a delivery for any other build.
|
||||
func KindOf(r BuildRequest) string {
|
||||
if r.ID == "" || r.Check != nil || r.DryRun {
|
||||
return KindCheck
|
||||
}
|
||||
return KindDelivery
|
||||
}
|
||||
|
||||
// DeleteAsk removes a waiting or dead ask from the queue it is in, at its sequence. Says the sequence it removed, 0 when
|
||||
// it was not there any more: taken and settled, or replaced by a newer request for its pull request.
|
||||
func DeleteAsk(_ context.Context, js *broker.JetStream, seat string, ask QueuedAsk) (uint64, error) {
|
||||
stream := ask.Stream
|
||||
if stream == "" {
|
||||
worker, _ := broker.HolderConsumerFor("", "", broker.DeclaredSeat{Name: seat, Accepts: []string{"build"}})
|
||||
stream = worker.Stream
|
||||
}
|
||||
err := js.Context().DeleteMsg(stream, ask.Seq)
|
||||
switch {
|
||||
case err == nil:
|
||||
return ask.Seq, nil
|
||||
case errors.Is(err, nats.ErrMsgNotFound) || errors.Is(err, jetstream.ErrMsgNotFound) ||
|
||||
strings.Contains(err.Error(), "no message found"):
|
||||
return 0, nil
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
Reference in New Issue
Block a user