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