]> source.dussan.org Git - gitea.git/commitdiff
Pools limit concurrent nums
authorUnknown <joe2010xtmf@163.com>
Thu, 20 Mar 2014 01:05:48 +0000 (21:05 -0400)
committerUnknown <joe2010xtmf@163.com>
Thu, 20 Mar 2014 01:05:48 +0000 (21:05 -0400)
README.md
conf/app.ini
gogs.go
models/user.go
modules/base/conf.go
modules/mailer/mail.go
modules/mailer/mailer.go
routers/user/user.go

index ce5fd5f6db4f431ebac9d12498f2db3635481568..b43e3c98a521da5eab235700bd26922e8093cc5f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language.
 
 Since we choose to use pure Go implementation of Git manipulation, Gogs certainly supports **ALL platforms**  that Go supports, including Linux, Max OS X, and Windows with **ZERO** dependency.
 
-##### Current version: 0.1.0 Alpha
+##### Current version: 0.1.1 Alpha
 
 ## Purpose
 
@@ -26,6 +26,7 @@ There are some very good products in this category such as [gitlab](http://gitla
 - User profile page.
 - Repository viewer.
 - Gravatar support.
+- Mail service(register).
 - Supports MySQL and PostgreSQL.
 
 ## Installation
index c2c299cf63f6fc6e2dac7c763db086256e9501b8..658f7c01512e37fafe6ccb75caf76edc00f974e2 100644 (file)
@@ -39,6 +39,8 @@ REGISTER_EMAIL_CONFIRM = false
 
 [mailer]
 ENABLED = false
+; Buffer length of channel, keep it as it is if you don't know what it is.
+SEND_BUFFER_LEN = 10
 ; Name displayed in mail title
 SUBJECT = %(APP_NAME)s
 ; Mail server
diff --git a/gogs.go b/gogs.go
index 106e8b1d933a3da957a9eac5be7564fd3dca2ab6..385b74217b75b914a0be4b5c3f7b6aa3ff175f76 100644 (file)
--- a/gogs.go
+++ b/gogs.go
@@ -20,7 +20,7 @@ import (
 // Test that go1.1 tag above is included in builds. main.go refers to this definition.
 const go11tag = true
 
-const APP_VER = "0.1.0.0319.1"
+const APP_VER = "0.1.1.0320.1"
 
 func init() {
        base.AppVer = APP_VER
index 3c31b3aff4a3ec0f5143587da2583fa0cbde819b..76cf2d20ce83f6f7e8f07c7a7d0716b0858c3467 100644 (file)
@@ -51,8 +51,7 @@ type User struct {
        Location      string
        Website       string
        IsActive      bool
-       Rands         string `xorm:"VARCHAR(10)"`
-       Expired       time.Time
+       Rands         string    `xorm:"VARCHAR(10)"`
        Created       time.Time `xorm:"created"`
        Updated       time.Time `xorm:"updated"`
 }
@@ -125,7 +124,6 @@ func RegisterUser(user *User) (*User, error) {
        user.LowerName = strings.ToLower(user.Name)
        user.Avatar = base.EncodeMd5(user.Email)
        user.AvatarEmail = user.Email
-       user.Expired = time.Now().Add(3 * 24 * time.Hour)
        user.Rands = GetUserSalt()
        if err = user.EncodePasswd(); err != nil {
                return nil, err
index b003dea50cc81b46f7f868afda895793b29b6c28..17ba3b879a431dcd331da0f1e3c9de4067a6e643 100644 (file)
@@ -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)),
index c1d12bba45a0e81212a386c6a3ee3e670312dd5c..92acd20efbd0d336bb509e26f7bd63caf8b28ce2 100644 (file)
@@ -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)
 }
index cc76acb26f9733fa10474091e2c5c8595aff0e2c..3823e01fa66e6169d5211a5db2d0b6d80e7a1e1d 100644 (file)
@@ -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
        }()
 }
 
index 32f458f83554ff5192112a1f0743e7f63e76a3cb..37070af3f91c2e996b6d27f723eacd2ea37a85ef 100644 (file)
@@ -249,6 +249,9 @@ func Activate(ctx *middleware.Context) {
                user.IsActive = true
                user.Rands = models.GetUserSalt()
                models.UpdateUser(user)
+
+               log.Trace("%s User activated: %s", ctx.Req.RequestURI, user.LowerName)
+
                ctx.Session.Set("userId", user.Id)
                ctx.Session.Set("userName", user.Name)
                ctx.Redirect("/", 302)