summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-03-19 21:05:48 -0400
committerUnknown <joe2010xtmf@163.com>2014-03-19 21:05:48 -0400
commit6f6862086047ba6902f51de3cb66eb3af04fffbd (patch)
treecad4673115913aa14413c6a7082359d99a5dd913 /modules
parent601c10309dd93c55c3c825c5a5c2384d46493589 (diff)
downloadgitea-6f6862086047ba6902f51de3cb66eb3af04fffbd.tar.gz
gitea-6f6862086047ba6902f51de3cb66eb3af04fffbd.zip
Pools limit concurrent nums
Diffstat (limited to 'modules')
-rw-r--r--modules/base/conf.go4
-rw-r--r--modules/mailer/mail.go6
-rw-r--r--modules/mailer/mailer.go44
3 files changed, 34 insertions, 20 deletions
diff --git a/modules/base/conf.go b/modules/base/conf.go
index b003dea50c..17ba3b879a 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<<uint(Cfg.MustInt(modeSec, "MAX_SIZE_SHIFT", 28)),
diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go
index c1d12bba45..92acd20efb 100644
--- a/modules/mailer/mail.go
+++ b/modules/mailer/mail.go
@@ -62,8 +62,7 @@ func SendRegisterMail(r *middleware.Render, user *models.User) {
msg := NewMailMessage([]string{user.Email}, subject, body)
msg.Info = fmt.Sprintf("UID: %d, send register mail", user.Id)
- // async send mail
- SendAsync(msg)
+ SendAsync(&msg)
}
// Send email verify active email.
@@ -83,6 +82,5 @@ func SendActiveMail(r *middleware.Render, user *models.User) {
msg := NewMailMessage([]string{user.Email}, subject, body)
msg.Info = fmt.Sprintf("UID: %d, send email verify mail", user.Id)
- // async send mail
- SendAsync(msg)
+ SendAsync(&msg)
}
diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go
index cc76acb26f..3823e01fa6 100644
--- a/modules/mailer/mailer.go
+++ b/modules/mailer/mailer.go
@@ -38,8 +38,34 @@ func (m Message) Content() string {
return content
}
+var mailQueue chan *Message
+
+func init() {
+ mailQueue = make(chan *Message, base.Cfg.MustInt("mailer", "SEND_BUFFER_LEN", 10))
+ go processMailQueue()
+}
+
+func processMailQueue() {
+ for {
+ select {
+ case msg := <-mailQueue:
+ num, err := Send(msg)
+ tos := strings.Join(msg.To, "; ")
+ info := ""
+ if err != nil {
+ if len(msg.Info) > 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
}()
}