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 --- README.md | 3 ++- conf/app.ini | 2 ++ gogs.go | 2 +- models/user.go | 4 +--- modules/base/conf.go | 4 +++- modules/mailer/mail.go | 6 ++---- modules/mailer/mailer.go | 44 +++++++++++++++++++++++++++++--------------- routers/user/user.go | 3 +++ 8 files changed, 43 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index ce5fd5f6db..b43e3c98a5 100644 --- 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 diff --git a/conf/app.ini b/conf/app.ini index c2c299cf63..658f7c0151 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -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 106e8b1d93..385b74217b 100644 --- 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 diff --git a/models/user.go b/models/user.go index 3c31b3aff4..76cf2d20ce 100644 --- a/models/user.go +++ b/models/user.go @@ -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 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< 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 }() } diff --git a/routers/user/user.go b/routers/user/user.go index 32f458f835..37070af3f9 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -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) -- cgit v1.2.3