You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

notification.go 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2016 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package notification
  5. import (
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/log"
  8. )
  9. type (
  10. notificationService struct {
  11. issueQueue chan issueNotificationOpts
  12. }
  13. issueNotificationOpts struct {
  14. issue *models.Issue
  15. notificationAuthorID int64
  16. }
  17. )
  18. var (
  19. // Service is the notification service
  20. Service = &notificationService{
  21. issueQueue: make(chan issueNotificationOpts, 100),
  22. }
  23. )
  24. func init() {
  25. go Service.Run()
  26. }
  27. func (ns *notificationService) Run() {
  28. for {
  29. select {
  30. case opts := <-ns.issueQueue:
  31. if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil {
  32. log.Error(4, "Was unable to create issue notification: %v", err)
  33. }
  34. }
  35. }
  36. }
  37. func (ns *notificationService) NotifyIssue(issue *models.Issue, notificationAuthorID int64) {
  38. ns.issueQueue <- issueNotificationOpts{
  39. issue,
  40. notificationAuthorID,
  41. }
  42. }