Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return error on stream error for retry #565

Merged
merged 3 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ func (a *agent) Start(ctx context.Context) error {

g.Go(func() error {
if err := a.spooler.start(ctx); err != nil {
return fmt.Errorf("spooler terminated: %w", err)
// only report error if context has not been canceled
if ctx.Err() == nil {
return fmt.Errorf("spooler terminated: %w", err)
}
}
return nil
})
Expand Down
9 changes: 7 additions & 2 deletions internal/agent/spooler.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,25 @@ func (s *spoolerDaemon) reinitialize(ctx context.Context) error {
}
// then spool events as they come in
for event := range sub {
s.handleEvent(event)
err = s.handleEvent(event)
if err != nil {
return err
}
}
return nil
}

func (s *spoolerDaemon) handleEvent(ev pubsub.Event) {
func (s *spoolerDaemon) handleEvent(ev pubsub.Event) error {
switch payload := ev.Payload.(type) {
case *run.Run:
s.handleRun(ev.Type, payload)
case string:
s.Info("stream update", "info", string(payload))
case error:
s.Error(payload, "stream update")
return payload
}
return nil
}

func (s *spoolerDaemon) handleRun(event pubsub.EventType, run *run.Run) {
Expand Down