Skip to content

Commit

Permalink
refactor: log on message skip and todo
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsNotGoodName committed Jan 2, 2022
1 parent df0057b commit bff7e5c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion left/smtp/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (s *session) Data(r io.Reader) error {
go func() {
err := s.app.MessageHandle(&req)
if err != nil {
log.Println("smtp.Data: could not send message:", err)
log.Println("smtp.Data: could not handle message:", err)
}
}()

Expand Down
20 changes: 12 additions & 8 deletions service/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ func NewEndpoint(endpointREPO domain.EndpointRepositoryPort) *Endpoint {
}

func (e *Endpoint) SendBridges(msg *domain.Message, bridges []*domain.Bridge) (domain.Status, error) {
// TODO: refactor entire method
if len(bridges) == 0 {
log.Println("app.messageSend: no valid bridges: skipped message", msg.UUID)
return domain.StatusSkipped, nil
}

var err error
var errGet error
sent := 0
skipped := 0
for _, bridge := range bridges {
Expand All @@ -31,27 +33,29 @@ func (e *Endpoint) SendBridges(msg *domain.Message, bridges []*domain.Bridge) (d

for _, name := range bridge.Endpoints {
var endpoint domain.EndpointPort
endpoint, err = e.endpointREPO.Get(name)
if err != nil {
endpoint, errGet = e.endpointREPO.Get(name)
if errGet != nil {
break
}

// TODO: worker pool
if err = endpoint.Send(emsg); err != nil {
log.Println("service.Endpoint.SendBridges:", err)
if errEnd := endpoint.Send(emsg); errEnd != nil {
log.Println("service.Endpoint.SendBridges:", errEnd)
} else {
sent++
}
}
}

if sent > 0 {
return domain.StatusSent, err
log.Println("app.messageSend: sent message", msg.UUID)
return domain.StatusSent, errGet
}

if skipped > 0 {
return domain.StatusSkipped, err
log.Println("app.messageSend: only_* produced empty message: skipped message", msg.UUID)
return domain.StatusSkipped, errGet
}

return domain.StatusFailed, err
return domain.StatusFailed, errGet
}

0 comments on commit bff7e5c

Please sign in to comment.