1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-06-16 14:37:46 +02:00

use goroutines for (most) emails

invite emails have been left alone so that email success message is
shown on web ui
This commit is contained in:
Harvey Tindall 2020-08-02 17:17:29 +01:00
parent 699489e435
commit f0be006e16

52
api.go
View File

@ -92,13 +92,15 @@ func (ctx *appContext) checkInvites() {
ctx.debug.Printf("%s: Expiry notification", code) ctx.debug.Printf("%s: Expiry notification", code)
for address, settings := range notify { for address, settings := range notify {
if settings["notify-expiry"] { if settings["notify-expiry"] {
if ctx.email.constructExpiry(code, data, ctx) != nil { go func() {
ctx.err.Printf("%s: Failed to construct expiry notification", code) if ctx.email.constructExpiry(code, data, ctx) != nil {
} else if ctx.email.send(address, ctx) != nil { ctx.err.Printf("%s: Failed to construct expiry notification", code)
ctx.err.Printf("%s: Failed to send expiry notification", code) } else if ctx.email.send(address, ctx) != nil {
} else { ctx.err.Printf("%s: Failed to send expiry notification", code)
ctx.info.Printf("Sent expiry notification to %s", address) } else {
} ctx.info.Printf("Sent expiry notification to %s", address)
}
}()
} }
} }
} }
@ -124,13 +126,15 @@ func (ctx *appContext) checkInvite(code string, used bool, username string) bool
ctx.debug.Printf("%s: Expiry notification", code) ctx.debug.Printf("%s: Expiry notification", code)
for address, settings := range notify { for address, settings := range notify {
if settings["notify-expiry"] { if settings["notify-expiry"] {
if ctx.email.constructExpiry(code, inv, ctx) != nil { go func() {
ctx.err.Printf("%s: Failed to construct expiry notification", code) if ctx.email.constructExpiry(code, inv, ctx) != nil {
} else if ctx.email.send(address, ctx) != nil { ctx.err.Printf("%s: Failed to construct expiry notification", code)
ctx.err.Printf("%s: Failed to send expiry notification", code) } else if ctx.email.send(address, ctx) != nil {
} else { ctx.err.Printf("%s: Failed to send expiry notification", code)
ctx.info.Printf("Sent expiry notification to %s", address) } else {
} ctx.info.Printf("Sent expiry notification to %s", address)
}
}()
} }
} }
} }
@ -212,15 +216,17 @@ func (ctx *appContext) NewUser(gc *gin.Context) {
if ctx.config.Section("notifications").Key("enabled").MustBool(false) { if ctx.config.Section("notifications").Key("enabled").MustBool(false) {
for address, settings := range invite.Notify { for address, settings := range invite.Notify {
if settings["notify-creation"] { if settings["notify-creation"] {
if ctx.email.constructCreated(req.Code, req.Username, req.Email, invite, ctx) != nil { go func() {
ctx.err.Printf("%s: Failed to construct user creation notification", req.Code) if ctx.email.constructCreated(req.Code, req.Username, req.Email, invite, ctx) != nil {
ctx.debug.Printf("%s: Error: %s", req.Code, err) ctx.err.Printf("%s: Failed to construct user creation notification", req.Code)
} else if ctx.email.send(address, ctx) != nil { ctx.debug.Printf("%s: Error: %s", req.Code, err)
ctx.err.Printf("%s: Failed to send user creation notification", req.Code) } else if ctx.email.send(address, ctx) != nil {
ctx.debug.Printf("%s: Error: %s", req.Code, err) ctx.err.Printf("%s: Failed to send user creation notification", req.Code)
} else { ctx.debug.Printf("%s: Error: %s", req.Code, err)
ctx.info.Printf("%s: Sent user creation notification to %s", req.Code, address) } else {
} ctx.info.Printf("%s: Sent user creation notification to %s", req.Code, address)
}
}()
} }
} }
} }