Skip to content

Commit f692ade

Browse files
committed
First version of notification service
1 parent 679d91a commit f692ade

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

modules/notification/notification.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package notification
2+
3+
import (
4+
"code.gitea.io/gitea/models"
5+
"code.gitea.io/gitea/modules/log"
6+
)
7+
8+
type notificationService struct {
9+
issueQueue chan *models.Issue
10+
}
11+
12+
var (
13+
// Service is the notification service
14+
Service = &notificationService{
15+
issueQueue: make(chan *models.Issue),
16+
}
17+
)
18+
19+
func init() {
20+
go Service.Run()
21+
}
22+
23+
func (ns *notificationService) Run() {
24+
for {
25+
select {
26+
case issue := <-ns.issueQueue:
27+
if err := models.CreateOrUpdateIssueNotifications(issue); err != nil {
28+
log.Error(4, "Was unable to create issue notification: %v", err)
29+
}
30+
}
31+
}
32+
}
33+
34+
func (ns *notificationService) NotifyIssue(issue *models.Issue) {
35+
ns.issueQueue <- issue
36+
}

routers/repo/issue.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"code.gitea.io/gitea/modules/context"
2424
"code.gitea.io/gitea/modules/log"
2525
"code.gitea.io/gitea/modules/markdown"
26+
"code.gitea.io/gitea/modules/notification"
2627
"code.gitea.io/gitea/modules/setting"
2728
)
2829

@@ -453,10 +454,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
453454
return
454455
}
455456

456-
if err := models.CreateOrUpdateIssueNotifications(issue); err != nil {
457-
ctx.Handle(500, "CreateOrUpdateIssueNotifications", err)
458-
return
459-
}
457+
notification.Service.NotifyIssue(issue)
460458

461459
log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
462460
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
@@ -903,10 +901,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
903901
return
904902
}
905903

906-
if err := models.CreateOrUpdateIssueNotifications(issue); err != nil {
907-
ctx.Handle(500, "CreateOrUpdateIssueNotifications", err)
908-
return
909-
}
904+
notification.Service.NotifyIssue(issue)
910905

911906
log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
912907
}

0 commit comments

Comments
 (0)