Skip to content

Commit

Permalink
Letting compensate method return error
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoomanfr committed Jun 26, 2022
1 parent a2252ee commit 187c959
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion internal/consumer/handler_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,14 @@ func (h *handlerCommand[T]) retry(msgBytes []byte) {
}

func (h *handlerCommand[T]) compensate(consumerMsg handler.HandlerMessage[T]) {
methodPath := reflection.MethodPath(h.compensate)
compensateMsgStream := make(chan handler.HandlerMessage[T])
go func(consumerMsg handler.HandlerMessage[T]) {
h.handler.Compensate(compensateMsgStream)
err := h.handler.Compensate(compensateMsgStream)
if err != nil {
log.Default().Println(formatter.FormatErr(methodPath, err))
return
}
}(consumerMsg)
compensateMsgStream <- consumerMsg
}
2 changes: 1 addition & 1 deletion pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type IMessage interface {

type IHandler[T IMessage] interface {
Handle(msg <-chan HandlerMessage[T]) error
Compensate(msg <-chan HandlerMessage[T])
Compensate(msg <-chan HandlerMessage[T]) error
}

type HandlerMessage[T IMessage] struct {
Expand Down

0 comments on commit 187c959

Please sign in to comment.