Skip to content

Commit

Permalink
fix: event handler listen to ctx.Done
Browse files Browse the repository at this point in the history
  • Loading branch information
GoshaDo committed Jan 9, 2025
1 parent 1c098a5 commit a6d1a48
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions pkg/event_handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,24 @@ func Start(ctx context.Context, stop context.CancelFunc, cfg *conf.GlobalConfig,
Notifier: notifier,
}
go func() {
for event := range watcher.ResultChan() {
err2 := handler.Handle(ctx, &event)
if err2 != nil {
log.Printf("[event handler] failed to Handle workflow event %s", err2) // ERROR
for {
select {
case <-ctx.Done():
log.Print("[event handler] context canceled, stopping watcher")
watcher.Stop()
return
case event, ok := <-watcher.ResultChan():
if !ok {
log.Print("[event handler] result channel closed")
watcher.Stop()
return
}
if err2 := handler.Handle(ctx, &event); err2 != nil {
log.Printf("[event handler] failed to Handle workflow event: %v", err2)
}
}
stop()
}
log.Print("[event handler] stopped work, closing watcher")
watcher.Stop()
stop()

}()
}

0 comments on commit a6d1a48

Please sign in to comment.