修复协程调度顺序错误
This commit is contained in:
jinnrry
2023-08-30 17:48:47 +08:00
parent f7078e7c8f
commit 12a79d9591
5 changed files with 31 additions and 24 deletions

View File

@@ -128,14 +128,16 @@ func Send(ctx *dto.Context, w http.ResponseWriter, req *http.Request) {
}
as := async.New(ctx)
for _, hook := range hooks.HookList {
if hook == nil {
continue
}
async.New(ctx).Process(func() {
hook.SendBefore(ctx, e)
})
as.WaitProcess(func(hk any) {
hk.(hooks.EmailHook).SendBefore(ctx, e)
}, hook)
}
as.Wait()
// 邮件落库
sql := "INSERT INTO email (type,subject, reply_to, from_name, from_address, `to`, bcc, cc, text, html, sender, attachments,spf_check, dkim_check, create_time,send_user_id,error) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
@@ -166,17 +168,18 @@ func Send(ctx *dto.Context, w http.ResponseWriter, req *http.Request) {
return
}
async.New(ctx).Process(func() {
async.New(ctx).Process(func(p any) {
errMsg := ""
err, sendErr := smtp_server.Send(ctx, e)
as2 := async.New(ctx)
for _, hook := range hooks.HookList {
if hook == nil {
continue
}
async.New(ctx).Process(func() {
hook.SendAfter(ctx, e, sendErr)
})
as2.WaitProcess(func(hk any) {
hk.(hooks.EmailHook).SendAfter(ctx, e, sendErr)
}, hook)
}
if err != nil {
@@ -192,7 +195,7 @@ func Send(ctx *dto.Context, w http.ResponseWriter, req *http.Request) {
}
}
})
}, nil)
response.NewSuccessResponse(i18n.GetText(ctx.Lang, "succ")).FPrint(w)
}