-
Notifications
You must be signed in to change notification settings - Fork 4
/
teams.go
59 lines (46 loc) · 1.18 KB
/
teams.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package service
import (
"github.com/pkg/errors"
"github.com/robfig/cron/v3"
"github.com/rs/zerolog/log"
"github.com/spatecon/gitlab-review-bot/internal/app/service/worker"
"github.com/spatecon/gitlab-review-bot/internal/pkg/logger"
)
func (s *Service) loadTeams() (err error) {
s.teams, err = s.r.Teams()
if err != nil {
return errors.Wrap(err, "failed to load teams")
}
return nil
}
func (s *Service) initNotifications() error {
l := logger.CronLogger{L: log.Logger}
s.cron = cron.New(cron.WithChain(
cron.Recover(l),
cron.SkipIfStillRunning(l),
))
for _, team := range s.teams {
if !team.Notifications.Enabled {
continue
}
if team.Notifications.IsEmpty() {
continue
}
_, ok := s.policies[team.Policy]
if !ok {
log.Warn().
Str("policy", string(team.Policy)).
Str("team_id", team.ID).
Msg("unknown policy while initializing notifications")
continue
}
wrk := worker.NewNotificationsWorker(team, s, s.slack)
_, err := s.cron.AddJob(team.Notifications.Cron, wrk)
if err != nil {
return errors.Wrapf(err,
"failed to add notification worker for %s team (%s)", team.ID, team.Notifications.Cron)
}
}
s.cron.Start()
return nil
}