v2.1.2
修复协程调度顺序错误
This commit is contained in:
parent
f7078e7c8f
commit
12a79d9591
@ -35,7 +35,7 @@ type Config struct {
|
|||||||
//go:embed tables/*
|
//go:embed tables/*
|
||||||
var tableConfig embed.FS
|
var tableConfig embed.FS
|
||||||
|
|
||||||
const Version = "2.1.1"
|
const Version = "2.1.2"
|
||||||
|
|
||||||
const DBTypeMySQL = "mysql"
|
const DBTypeMySQL = "mysql"
|
||||||
const DBTypeSQLite = "sqlite"
|
const DBTypeSQLite = "sqlite"
|
||||||
|
|||||||
@ -128,14 +128,16 @@ func Send(ctx *dto.Context, w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
as := async.New(ctx)
|
||||||
for _, hook := range hooks.HookList {
|
for _, hook := range hooks.HookList {
|
||||||
if hook == nil {
|
if hook == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
async.New(ctx).Process(func() {
|
as.WaitProcess(func(hk any) {
|
||||||
hook.SendBefore(ctx, e)
|
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
async.New(ctx).Process(func() {
|
async.New(ctx).Process(func(p any) {
|
||||||
errMsg := ""
|
errMsg := ""
|
||||||
err, sendErr := smtp_server.Send(ctx, e)
|
err, sendErr := smtp_server.Send(ctx, e)
|
||||||
|
|
||||||
|
as2 := async.New(ctx)
|
||||||
for _, hook := range hooks.HookList {
|
for _, hook := range hooks.HookList {
|
||||||
if hook == nil {
|
if hook == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
async.New(ctx).Process(func() {
|
as2.WaitProcess(func(hk any) {
|
||||||
hook.SendAfter(ctx, e, sendErr)
|
hk.(hooks.EmailHook).SendAfter(ctx, e, sendErr)
|
||||||
})
|
}, hook)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
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)
|
response.NewSuccessResponse(i18n.GetText(ctx.Lang, "succ")).FPrint(w)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,14 +23,16 @@ func (s *Session) Data(r io.Reader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
as1 := async.New(nil)
|
||||||
for _, hook := range hooks.HookList {
|
for _, hook := range hooks.HookList {
|
||||||
if hook == nil {
|
if hook == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
async.New(nil).Process(func() {
|
as1.WaitProcess(func(hk any) {
|
||||||
hook.ReceiveParseBefore(emailData)
|
hk.(hooks.EmailHook).ReceiveParseBefore(emailData)
|
||||||
})
|
}, hook)
|
||||||
}
|
}
|
||||||
|
as1.Wait()
|
||||||
|
|
||||||
log.Infof("邮件原始内容: %s", emailData)
|
log.Infof("邮件原始内容: %s", emailData)
|
||||||
|
|
||||||
@ -55,14 +57,16 @@ func (s *Session) Data(r io.Reader) error {
|
|||||||
spfV = 1
|
spfV = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
as2 := async.New(nil)
|
||||||
for _, hook := range hooks.HookList {
|
for _, hook := range hooks.HookList {
|
||||||
if hook == nil {
|
if hook == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
async.New(nil).Process(func() {
|
as2.WaitProcess(func(hk any) {
|
||||||
hook.ReceiveParseAfter(email)
|
hk.(hooks.EmailHook).ReceiveParseAfter(email)
|
||||||
})
|
}, hook)
|
||||||
}
|
}
|
||||||
|
as2.Wait()
|
||||||
|
|
||||||
sql := "INSERT INTO email (send_date, subject, reply_to, from_name, from_address, `to`, bcc, cc, text, html, sender, attachments,spf_check, dkim_check, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
sql := "INSERT INTO email (send_date, subject, reply_to, from_name, from_address, `to`, bcc, cc, text, html, sender, attachments,spf_check, dkim_check, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
||||||
_, err = db.Instance.Exec(sql,
|
_, err = db.Instance.Exec(sql,
|
||||||
|
|||||||
@ -61,7 +61,7 @@ func Send(ctx *dto.Context, e *parsemail.Email) (error, map[string]error) {
|
|||||||
for domain, tos := range toByDomain {
|
for domain, tos := range toByDomain {
|
||||||
domain := domain
|
domain := domain
|
||||||
tos := tos
|
tos := tos
|
||||||
as.WaitProcess(func() {
|
as.WaitProcess(func(p any) {
|
||||||
|
|
||||||
err := smtp.SendMail("", domain.mxHost+":25", nil, e.From.EmailAddress, buildAddress(tos), b)
|
err := smtp.SendMail("", domain.mxHost+":25", nil, e.From.EmailAddress, buildAddress(tos), b)
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ func Send(ctx *dto.Context, e *parsemail.Email) (error, map[string]error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
errMap[domain.domain] = err
|
errMap[domain.domain] = err
|
||||||
})
|
}, nil)
|
||||||
}
|
}
|
||||||
as.Wait()
|
as.Wait()
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Callback func()
|
type Callback func(params any)
|
||||||
|
|
||||||
type Async struct {
|
type Async struct {
|
||||||
wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
@ -27,25 +27,25 @@ func (as *Async) LastError() error {
|
|||||||
return as.lastError
|
return as.lastError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (as *Async) WaitProcess(callback Callback) {
|
func (as *Async) WaitProcess(callback Callback, params any) {
|
||||||
if as.wg == nil {
|
if as.wg == nil {
|
||||||
as.wg = &sync.WaitGroup{}
|
as.wg = &sync.WaitGroup{}
|
||||||
}
|
}
|
||||||
as.wg.Add(1)
|
as.wg.Add(1)
|
||||||
as.Process(func() {
|
as.Process(func(params any) {
|
||||||
defer as.wg.Done()
|
defer as.wg.Done()
|
||||||
callback()
|
callback(params)
|
||||||
})
|
}, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (as *Async) Process(callback Callback) {
|
func (as *Async) Process(callback Callback, params any) {
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
as.lastError = as.HandleErrRecover(err)
|
as.lastError = as.HandleErrRecover(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
callback()
|
callback(params)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user