@@ -7,14 +7,17 @@ package ui
7
7
import (
8
8
"code.gitea.io/gitea/models"
9
9
"code.gitea.io/gitea/modules/git"
10
+ "code.gitea.io/gitea/modules/graceful"
10
11
"code.gitea.io/gitea/modules/log"
11
12
"code.gitea.io/gitea/modules/notification/base"
13
+ "code.gitea.io/gitea/modules/queue"
14
+ "code.gitea.io/gitea/modules/setting"
12
15
)
13
16
14
17
type (
15
18
notificationService struct {
16
19
base.NullNotifier
17
- issueQueue chan issueNotificationOpts
20
+ issueQueue queue. Queue
18
21
}
19
22
20
23
issueNotificationOpts struct {
@@ -30,19 +33,24 @@ var (
30
33
31
34
// NewNotifier create a new notificationService notifier
32
35
func NewNotifier () base.Notifier {
33
- return & notificationService {
34
- issueQueue : make ( chan issueNotificationOpts , 100 ),
35
- }
36
+ ns := & notificationService {}
37
+ ns . issueQueue = setting . CreateQueue ( "notification-service" , ns . handle , issueNotificationOpts {})
38
+ return ns
36
39
}
37
40
38
- func (ns * notificationService ) Run () {
39
- for opts := range ns .issueQueue {
41
+ func (ns * notificationService ) handle (data ... queue.Data ) {
42
+ for _ , datum := range data {
43
+ opts := datum .(issueNotificationOpts )
40
44
if err := models .CreateOrUpdateIssueNotifications (opts .issueID , opts .commentID , opts .notificationAuthorID ); err != nil {
41
45
log .Error ("Was unable to create issue notification: %v" , err )
42
46
}
43
47
}
44
48
}
45
49
50
+ func (ns * notificationService ) Run () {
51
+ graceful .GetManager ().RunWithShutdownFns (ns .issueQueue .Run )
52
+ }
53
+
46
54
func (ns * notificationService ) NotifyCreateIssueComment (doer * models.User , repo * models.Repository ,
47
55
issue * models.Issue , comment * models.Comment ) {
48
56
var opts = issueNotificationOpts {
@@ -52,35 +60,39 @@ func (ns *notificationService) NotifyCreateIssueComment(doer *models.User, repo
52
60
if comment != nil {
53
61
opts .commentID = comment .ID
54
62
}
55
- ns .issueQueue <- opts
63
+ _ = ns .issueQueue . Push ( opts )
56
64
}
57
65
58
66
func (ns * notificationService ) NotifyNewIssue (issue * models.Issue ) {
59
- ns .issueQueue <- issueNotificationOpts {
67
+ _ = ns .issueQueue . Push ( issueNotificationOpts {
60
68
issueID : issue .ID ,
61
69
notificationAuthorID : issue .Poster .ID ,
62
- }
70
+ })
63
71
}
64
72
65
73
func (ns * notificationService ) NotifyIssueChangeStatus (doer * models.User , issue * models.Issue , actionComment * models.Comment , isClosed bool ) {
66
74
ns .issueQueue <- issueNotificationOpts {
67
75
issueID : issue .ID ,
68
76
notificationAuthorID : doer .ID ,
69
- }
77
+ })
70
78
}
71
79
72
80
func (ns * notificationService ) NotifyMergePullRequest (pr * models.PullRequest , doer * models.User , gitRepo * git.Repository ) {
73
- ns .issueQueue <- issueNotificationOpts {
81
+ _ = ns .issueQueue . Push ( issueNotificationOpts {
74
82
issueID : pr .Issue .ID ,
75
83
notificationAuthorID : doer .ID ,
76
- }
84
+ })
77
85
}
78
86
79
87
func (ns * notificationService ) NotifyNewPullRequest (pr * models.PullRequest ) {
80
- ns .issueQueue <- issueNotificationOpts {
88
+ if err := pr .LoadIssue (); err != nil {
89
+ log .Error ("Unable to load issue: %d for pr: %d: Error: %v" , pr .IssueID , pr .ID , err )
90
+ return
91
+ }
92
+ _ = ns .issueQueue .Push (issueNotificationOpts {
81
93
issueID : pr .Issue .ID ,
82
94
notificationAuthorID : pr .Issue .PosterID ,
83
- }
95
+ })
84
96
}
85
97
86
98
func (ns * notificationService ) NotifyPullRequestReview (pr * models.PullRequest , r * models.Review , c * models.Comment ) {
@@ -91,5 +103,5 @@ func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r
91
103
if c != nil {
92
104
opts .commentID = c .ID
93
105
}
94
- ns .issueQueue <- opts
106
+ _ = ns .issueQueue . Push ( opts )
95
107
}
0 commit comments