Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Testcenter outdated warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dreske committed Oct 10, 2022
1 parent 159f7d3 commit 920fb37
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/cmd/backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ func main() {
}()

go bugReportsService.PublishScheduler()
go operatorsService.OperatorNotificationScheduler()
go centersService.CenterNotificationScheduler()
//go operatorsService.OperatorNotificationScheduler()
//go centersService.CenterNotificationScheduler()

signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT)
Expand Down
5 changes: 3 additions & 2 deletions src/repositories/centers.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,10 @@ func (r *centersRepository) FindCentersForNotification(ctx context.Context, last
err := r.GetTX(ctx).
Raw(fmt.Sprintf(`
select c.*
from centers c
from centers c
join operators o on c.operator_uuid = o.uuid
where o.bug_reports_receiver = 'center'
where (c.visible != false and (c.enter_date is null or c.enter_date < now()) and (c.leave_date is null or c.leave_date > now()))
and o.bug_reports_receiver = 'center'
and c.last_update < now() - interval '%d weeks'
and ((c.notified < now() - interval '%d weeks') or c.notified is null)`, lastUpdateAge, renotifyInterval)).
Find(&result).
Expand Down
9 changes: 5 additions & 4 deletions src/repositories/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ func (r *operatorsRepository) FindOperatorsForNotification(ctx context.Context,
err := r.GetTX(ctx).
Raw(fmt.Sprintf(`
select o.*
from operators o
from operators o
join centers c on o.uuid = c.operator_uuid
where (o.bug_reports_receiver = 'operator')
where (c.visible != false and (c.enter_date is null or c.enter_date < now()) and (c.leave_date is null or c.leave_date > now()))
and (o.bug_reports_receiver = 'operator')
and ((o.notified < now() - interval '%d weeks') or o.notified is null)
and (o.notification_token is null)
group by o.uuid
having max(c.last_update) < now() - interval '%d weeks'`, renotifyInterval, lastUpdateAge)).
group by o.uuid
having max(c.last_update) < now() - interval '%d weeks'`, renotifyInterval, lastUpdateAge)).
Find(&result).
Error

Expand Down
7 changes: 6 additions & 1 deletion src/services/centers.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ func (s *centersService) ProcessCenterNotification(ctx context.Context, center d
}
logrus.WithField("center", center.UUID).Info("Processing center notification")

if center.Email == nil {
return errors.New("invalid email")
}
if err := s.mailService.ProcessTemplate(ctx,
*center.Email,
"center.notification.template",
Expand All @@ -256,7 +259,9 @@ func (s *centersService) ProcessCenterNotifications(ctx context.Context) error {
logrus.WithField("count", len(centers)).Info("Processing center notifications")
for _, center := range centers {
if err := s.ProcessCenterNotification(ctx, center); err != nil {
logrus.WithError(err).Error("Error processing center notification")
logrus.WithError(err).
WithField("center", center.UUID).
Error("Error processing center notification")
}
}
return nil
Expand Down
10 changes: 8 additions & 2 deletions src/services/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func (o *operatorsService) ProcessOperatorNotification(ctx context.Context, oper
operator.NotificationToken = &token
}

if operator.Email == nil {
return errors.New("invalid email")
}

if err := o.mailService.ProcessTemplate(ctx,
*operator.Email,
"operator.notification.template",
Expand All @@ -103,10 +107,12 @@ func (o *operatorsService) ProcessOperatorNotifications(ctx context.Context) err
logrus.WithError(err).Error("Error getting operators")
return err
}
logrus.WithField("count", len(operators)).Info("Processing operator verifications")
logrus.WithField("count", len(operators)).Info("Processing operator notifications")
for _, operator := range operators {
if err := o.ProcessOperatorNotification(ctx, operator); err != nil {
logrus.WithError(err).Error("Error processing operator notification")
logrus.WithError(err).
WithField("operator", operator.UUID).
Error("Error processing operator notification")
}
}
return nil
Expand Down

0 comments on commit 920fb37

Please sign in to comment.