feat/refactor #12

Open
daniel.w wants to merge 6 commits from feat/refactor into main
4 changed files with 13 additions and 9 deletions
Showing only changes of commit 2921bc9869 - Show all commits

View File

@ -6,6 +6,7 @@ import (
useD "app-cloudep-notification-service/pkg/domain/usecase" useD "app-cloudep-notification-service/pkg/domain/usecase"
"app-cloudep-notification-service/pkg/repository" "app-cloudep-notification-service/pkg/repository"
"app-cloudep-notification-service/pkg/usecase" "app-cloudep-notification-service/pkg/usecase"
"code.30cm.net/digimon/library-go/errs" "code.30cm.net/digimon/library-go/errs"
"code.30cm.net/digimon/library-go/errs/code" "code.30cm.net/digimon/library-go/errs/code"
) )
@ -75,6 +76,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
} }
uc := usecase.MustDeliveryUseCase(param) uc := usecase.MustDeliveryUseCase(param)
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,
DeliveryUseCase: uc, DeliveryUseCase: uc,

View File

@ -2,7 +2,8 @@ package main
import ( import (
"flag" "flag"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"app-cloudep-notification-service/gen_result/pb/notification" "app-cloudep-notification-service/gen_result/pb/notification"
"app-cloudep-notification-service/internal/config" "app-cloudep-notification-service/internal/config"
@ -34,6 +35,6 @@ func main() {
}) })
defer s.Stop() defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn) logx.Infof("Starting rpc server at %s...\n", c.ListenOn)
s.Start() s.Start()
} }

View File

@ -50,9 +50,7 @@ func (use *AwsEmailDeliveryRepository) SendMail(ctx context.Context, req reposit
err := use.Pool.Submit(func() { err := use.Pool.Submit(func() {
// 設置郵件參數 // 設置郵件參數
to := make([]string, 0, len(req.To)) to := make([]string, 0, len(req.To))
for _, item := range req.To { to = append(to, req.To...)
to = append(to, item)
}
input := &ses.SendEmailInput{ input := &ses.SendEmailInput{
Destination: &types.Destination{ Destination: &types.Destination{
@ -74,9 +72,12 @@ func (use *AwsEmailDeliveryRepository) SendMail(ctx context.Context, req reposit
} }
// 發送郵件 // 發送郵件
//TODO 不明原因送不出去,會被 context cancel 這裡先把它手動加到100sec // TODO 不明原因送不出去,會被 context cancel 這裡先把它手動加到100sec
c, _ := context.WithTimeout(context.Background(), 100*time.Second) newCtx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
if _, err := use.Client.SendEmail(c, input); err != nil { defer cancel()
//nolint:contextcheck
if _, err := use.Client.SendEmail(newCtx, input); err != nil {
_ = domain.ThirdPartyErrorL( _ = domain.ThirdPartyErrorL(
code.CloudEPNotification, code.CloudEPNotification,
domain.FailedToSendEmailErrorCode, domain.FailedToSendEmailErrorCode,

View File

@ -31,7 +31,7 @@ func MustSMTPUseCase(param SMTPMailUseCaseParam) repository.MailRepository {
} }
} }
func (repo *SMTPMailRepository) SendMail(ctx context.Context, req repository.MailReq) error { func (repo *SMTPMailRepository) SendMail(_ context.Context, req repository.MailReq) error {
// 用 goroutine pool 送,否則會超時 // 用 goroutine pool 送,否則會超時
err := repo.Pool.Submit(func() { err := repo.Pool.Submit(func() {
m := gomail.NewMessage() m := gomail.NewMessage()