mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Pools limit concurrent nums
This commit is contained in:
		| @@ -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. | 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 | ## Purpose | ||||||
|  |  | ||||||
| @@ -26,6 +26,7 @@ There are some very good products in this category such as [gitlab](http://gitla | |||||||
| - User profile page. | - User profile page. | ||||||
| - Repository viewer. | - Repository viewer. | ||||||
| - Gravatar support. | - Gravatar support. | ||||||
|  | - Mail service(register). | ||||||
| - Supports MySQL and PostgreSQL. | - Supports MySQL and PostgreSQL. | ||||||
|  |  | ||||||
| ## Installation | ## Installation | ||||||
|   | |||||||
| @@ -39,6 +39,8 @@ REGISTER_EMAIL_CONFIRM = false | |||||||
|  |  | ||||||
| [mailer] | [mailer] | ||||||
| ENABLED = false | 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 | ; Name displayed in mail title | ||||||
| SUBJECT = %(APP_NAME)s | SUBJECT = %(APP_NAME)s | ||||||
| ; Mail server | ; Mail server | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							| @@ -20,7 +20,7 @@ import ( | |||||||
| // Test that go1.1 tag above is included in builds. main.go refers to this definition. | // Test that go1.1 tag above is included in builds. main.go refers to this definition. | ||||||
| const go11tag = true | const go11tag = true | ||||||
|  |  | ||||||
| const APP_VER = "0.1.0.0319.1" | const APP_VER = "0.1.1.0320.1" | ||||||
|  |  | ||||||
| func init() { | func init() { | ||||||
| 	base.AppVer = APP_VER | 	base.AppVer = APP_VER | ||||||
|   | |||||||
| @@ -51,8 +51,7 @@ type User struct { | |||||||
| 	Location      string | 	Location      string | ||||||
| 	Website       string | 	Website       string | ||||||
| 	IsActive      bool | 	IsActive      bool | ||||||
| 	Rands         string `xorm:"VARCHAR(10)"` | 	Rands         string    `xorm:"VARCHAR(10)"` | ||||||
| 	Expired       time.Time |  | ||||||
| 	Created       time.Time `xorm:"created"` | 	Created       time.Time `xorm:"created"` | ||||||
| 	Updated       time.Time `xorm:"updated"` | 	Updated       time.Time `xorm:"updated"` | ||||||
| } | } | ||||||
| @@ -125,7 +124,6 @@ func RegisterUser(user *User) (*User, error) { | |||||||
| 	user.LowerName = strings.ToLower(user.Name) | 	user.LowerName = strings.ToLower(user.Name) | ||||||
| 	user.Avatar = base.EncodeMd5(user.Email) | 	user.Avatar = base.EncodeMd5(user.Email) | ||||||
| 	user.AvatarEmail = user.Email | 	user.AvatarEmail = user.Email | ||||||
| 	user.Expired = time.Now().Add(3 * 24 * time.Hour) |  | ||||||
| 	user.Rands = GetUserSalt() | 	user.Rands = GetUserSalt() | ||||||
| 	if err = user.EncodePasswd(); err != nil { | 	if err = user.EncodePasswd(); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
|   | |||||||
| @@ -91,9 +91,11 @@ func newLogService() { | |||||||
| 	case "console": | 	case "console": | ||||||
| 		config = fmt.Sprintf(`{"level":%s}`, level) | 		config = fmt.Sprintf(`{"level":%s}`, level) | ||||||
| 	case "file": | 	case "file": | ||||||
|  | 		logPath := Cfg.MustValue(modeSec, "FILE_NAME", "log/gogs.log") | ||||||
|  | 		os.MkdirAll(path.Dir(logPath), os.ModePerm) | ||||||
| 		config = fmt.Sprintf( | 		config = fmt.Sprintf( | ||||||
| 			`{"level":%s,"filename":%s,"rotate":%v,"maxlines":%d,"maxsize",%d,"daily":%v,"maxdays":%d}`, level, | 			`{"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.MustBool(modeSec, "LOG_ROTATE", true), | ||||||
| 			Cfg.MustInt(modeSec, "MAX_LINES", 1000000), | 			Cfg.MustInt(modeSec, "MAX_LINES", 1000000), | ||||||
| 			1<<uint(Cfg.MustInt(modeSec, "MAX_SIZE_SHIFT", 28)), | 			1<<uint(Cfg.MustInt(modeSec, "MAX_SIZE_SHIFT", 28)), | ||||||
|   | |||||||
| @@ -62,8 +62,7 @@ func SendRegisterMail(r *middleware.Render, user *models.User) { | |||||||
| 	msg := NewMailMessage([]string{user.Email}, subject, body) | 	msg := NewMailMessage([]string{user.Email}, subject, body) | ||||||
| 	msg.Info = fmt.Sprintf("UID: %d, send register mail", user.Id) | 	msg.Info = fmt.Sprintf("UID: %d, send register mail", user.Id) | ||||||
|  |  | ||||||
| 	// async send mail | 	SendAsync(&msg) | ||||||
| 	SendAsync(msg) |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // Send email verify active email. | // 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 := NewMailMessage([]string{user.Email}, subject, body) | ||||||
| 	msg.Info = fmt.Sprintf("UID: %d, send email verify mail", user.Id) | 	msg.Info = fmt.Sprintf("UID: %d, send email verify mail", user.Id) | ||||||
|  |  | ||||||
| 	// async send mail | 	SendAsync(&msg) | ||||||
| 	SendAsync(msg) |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -38,8 +38,34 @@ func (m Message) Content() string { | |||||||
| 	return content | 	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 | // 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, "; ")) | 	log.Trace("Sending mails to: %s", strings.Join(msg.To, "; ")) | ||||||
| 	host := strings.Split(base.MailService.Host, ":") | 	host := strings.Split(base.MailService.Host, ":") | ||||||
|  |  | ||||||
| @@ -82,21 +108,9 @@ func Send(msg Message) (int, error) { | |||||||
| } | } | ||||||
|  |  | ||||||
| // Async Send mail message | // Async Send mail message | ||||||
| func SendAsync(msg Message) { | func SendAsync(msg *Message) { | ||||||
| 	// TODO may be need pools limit concurrent nums |  | ||||||
| 	go func() { | 	go func() { | ||||||
| 		num, err := Send(msg) | 		mailQueue <- 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)) |  | ||||||
| 	}() | 	}() | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -249,6 +249,9 @@ func Activate(ctx *middleware.Context) { | |||||||
| 		user.IsActive = true | 		user.IsActive = true | ||||||
| 		user.Rands = models.GetUserSalt() | 		user.Rands = models.GetUserSalt() | ||||||
| 		models.UpdateUser(user) | 		models.UpdateUser(user) | ||||||
|  |  | ||||||
|  | 		log.Trace("%s User activated: %s", ctx.Req.RequestURI, user.LowerName) | ||||||
|  |  | ||||||
| 		ctx.Session.Set("userId", user.Id) | 		ctx.Session.Set("userId", user.Id) | ||||||
| 		ctx.Session.Set("userName", user.Name) | 		ctx.Session.Set("userName", user.Name) | ||||||
| 		ctx.Redirect("/", 302) | 		ctx.Redirect("/", 302) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user