Skip to content

Commit

Permalink
fix failure case for domain-event publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
IzumiSy committed Sep 1, 2021
1 parent f863037 commit 6f95c24
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion domains/usecases/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ func (uc AuthenticateUsecase) Build(params AuthenticateParam) domains.Unauthoriz
UserID: auth.User().ID().String(),
CreatedAt: time.Now(),
}

// Eventのpublishに失敗しても意図的にエラーはレスポンスせずErrorのレポートのみとしておく
// 非同期処理のエラーは別途手動で復旧作業を行う
if err := uc.Publisher.Publish(event); err.NotNil() {
uc.Logger.Errorf(uc.Ctx, "Failed publishing event: %s", err.Error())
} else {
uc.Logger.Infof(uc.Ctx, "Event published: %s", event.ID())
}

uc.Logger.Infof(uc.Ctx, "Event published: %s", event.ID())
uc.OutputPort.Write(session)
})
}
Expand Down
6 changes: 5 additions & 1 deletion domains/usecases/create_todo.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ func (uc CreateTodoUsecase) Build(params CreateTodoParam) domains.AuthorizedUsec
Description: newTodo.Description().Value(),
CreatedAt: time.Now(),
}

// Eventのpublishに失敗しても意図的にエラーはレスポンスせずErrorのレポートのみとしておく
// 非同期処理のエラーは別途手動で復旧作業を行う
if err := uc.Publisher.Publish(event); err.NotNil() {
uc.Logger.Errorf(uc.Ctx, "Failed publishing event: %s", err.Error())
} else {
uc.Logger.Infof(uc.Ctx, "Event published: %s", event.ID())
}

uc.Logger.Infof(uc.Ctx, "Event published: %s", event.ID())
uc.OutputPort.Write(newTodo)
})
}
Expand Down
6 changes: 5 additions & 1 deletion domains/usecases/signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ func (uc SignupUsecase) Build(params SignupParam) domains.UnauthorizedUsecase {
Name_: auth.User().Name().Value(),
CreatedAt: time.Now(),
}

// Eventのpublishに失敗しても意図的にエラーはレスポンスせずErrorのレポートのみとしておく
// 非同期処理のエラーは別途手動で復旧作業を行う
if err := uc.Publisher.Publish(event); err.NotNil() {
uc.Logger.Errorf(uc.Ctx, "Failed publishing event: %s", err.Error())
} else {
uc.Logger.Infof(uc.Ctx, "Event published: %s", event.ID())
}

uc.Logger.Infof(uc.Ctx, "Event published: %s", event.ID())
uc.OutputPort.Write(auth)
})
}
Expand Down

0 comments on commit 6f95c24

Please sign in to comment.