diff options
author | Andrey Nering <andrey.nering@gmail.com> | 2016-12-30 14:44:54 -0200 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2016-12-31 00:44:54 +0800 |
commit | 42904cb98a4b8e7accdac90bc9f06347cb0521f7 (patch) | |
tree | ff7b39817584c93ad9afd2d2136f51f5d4ddb0a0 /modules/notification | |
parent | 37eec6c9b7056e1e05d0067aef86d2e61d67f757 (diff) | |
download | gitea-42904cb98a4b8e7accdac90bc9f06347cb0521f7.tar.gz gitea-42904cb98a4b8e7accdac90bc9f06347cb0521f7.zip |
Notification - Step 1 (#523)
* Notification - Step 1
* Add copyright headers
* Cache issue and repository on notification model
Diffstat (limited to 'modules/notification')
-rw-r--r-- | modules/notification/notification.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/modules/notification/notification.go b/modules/notification/notification.go new file mode 100644 index 0000000000..ffe885240b --- /dev/null +++ b/modules/notification/notification.go @@ -0,0 +1,50 @@ +// Copyright 2016 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package notification + +import ( + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/log" +) + +type ( + notificationService struct { + issueQueue chan issueNotificationOpts + } + + issueNotificationOpts struct { + issue *models.Issue + notificationAuthorID int64 + } +) + +var ( + // Service is the notification service + Service = ¬ificationService{ + issueQueue: make(chan issueNotificationOpts, 100), + } +) + +func init() { + go Service.Run() +} + +func (ns *notificationService) Run() { + for { + select { + case opts := <-ns.issueQueue: + if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil { + log.Error(4, "Was unable to create issue notification: %v", err) + } + } + } +} + +func (ns *notificationService) NotifyIssue(issue *models.Issue, notificationAuthorID int64) { + ns.issueQueue <- issueNotificationOpts{ + issue, + notificationAuthorID, + } +} |