Skip to content

Commit

Permalink
Handle new gitmon protocol
Browse files Browse the repository at this point in the history
The gitmon scheduler is not able to parse the new gitmon
message format that changed to `wait <delay> <reasons>\n` and `fail <delay> <reasons>\n`.

This commit tries to fix that parsing.
  • Loading branch information
elhmn committed Dec 22, 2023
1 parent 5b9eba9 commit 569e55b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions internal/governor/governor.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ func update(w io.Writer, ud updateData) error {

type WaitError struct {
Duration time.Duration
Reason string
}

func newWaitError(duration time.Duration) error {
func newWaitError(duration time.Duration, reason string) error {
return WaitError{
Duration: duration,
Reason: reason,
}
}

Expand Down Expand Up @@ -138,11 +140,13 @@ func schedule(r *bufio.Reader, w io.Writer, sideband io.Writer) error {
sideband.Write(b)
}

words := strings.SplitN(line, " ", 3)
switch words[0] {
case "continue":
return nil
case "wait":
duration := 1 * time.Second
reason := ""
if len(words) > 1 {
d, err := strconv.Atoi(words[1])
if err != nil {
Expand All @@ -151,11 +155,14 @@ func schedule(r *bufio.Reader, w io.Writer, sideband io.Writer) error {
duration = time.Duration(d) * time.Second
}
}
return newWaitError(duration)
if len(words) > 2 {
reason = words[2]
}
return newWaitError(duration, reason)
case "fail":
reason := "UNKNOWN"
if len(words) > 1 {
reason = words[1]
reason = strings.Join(words[1:], " ")
}
return newFailError(reason)
default:
Expand Down

0 comments on commit 569e55b

Please sign in to comment.