From 6f6862086047ba6902f51de3cb66eb3af04fffbd Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 19 Mar 2014 21:05:48 -0400 Subject: Pools limit concurrent nums --- modules/base/conf.go | 4 +++- modules/mailer/mail.go | 6 ++---- modules/mailer/mailer.go | 44 +++++++++++++++++++++++++++++--------------- 3 files changed, 34 insertions(+), 20 deletions(-) (limited to 'modules') diff --git a/modules/base/conf.go b/modules/base/conf.go index b003dea5..17ba3b87 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -91,9 +91,11 @@ func newLogService() { case "console": config = fmt.Sprintf(`{"level":%s}`, level) case "file": + logPath := Cfg.MustValue(modeSec, "FILE_NAME", "log/gogs.log") + os.MkdirAll(path.Dir(logPath), os.ModePerm) config = fmt.Sprintf( `{"level":%s,"filename":%s,"rotate":%v,"maxlines":%d,"maxsize",%d,"daily":%v,"maxdays":%d}`, level, - Cfg.MustValue(modeSec, "FILE_NAME", "log/gogs.log"), + logPath, Cfg.MustBool(modeSec, "LOG_ROTATE", true), Cfg.MustInt(modeSec, "MAX_LINES", 1000000), 1< 0 { + info = ", info: " + msg.Info + } + log.Error(fmt.Sprintf("Async sent email %d succeed, not send emails: %s%s err: %s", num, tos, info, err)) + return + } + log.Trace(fmt.Sprintf("Async sent email %d succeed, sent emails: %s%s", num, tos, info)) + } + } +} + // Direct Send mail message -func Send(msg Message) (int, error) { +func Send(msg *Message) (int, error) { log.Trace("Sending mails to: %s", strings.Join(msg.To, "; ")) host := strings.Split(base.MailService.Host, ":") @@ -82,21 +108,9 @@ func Send(msg Message) (int, error) { } // Async Send mail message -func SendAsync(msg Message) { - // TODO may be need pools limit concurrent nums +func SendAsync(msg *Message) { go func() { - num, err := Send(msg) - tos := strings.Join(msg.To, "; ") - info := "" - if err != nil { - if len(msg.Info) > 0 { - info = ", info: " + msg.Info - } - // log failed - log.Error(fmt.Sprintf("Async sent email %d succeed, not send emails: %s%s err: %s", num, tos, info, err)) - return - } - log.Trace(fmt.Sprintf("Async sent email %d succeed, sent emails: %s%s", num, tos, info)) + mailQueue <- msg }() } -- cgit v1.2.3