From 920fb37770928a059f594d69d92d2f9eb547625c Mon Sep 17 00:00:00 2001 From: Dirk Reske Date: Mon, 10 Oct 2022 08:42:21 +0200 Subject: [PATCH] Testcenter outdated warnings --- src/cmd/backend/main.go | 4 ++-- src/repositories/centers.go | 5 +++-- src/repositories/operators.go | 9 +++++---- src/services/centers.go | 7 ++++++- src/services/operators.go | 10 ++++++++-- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/cmd/backend/main.go b/src/cmd/backend/main.go index b8b3c77..405cae6 100644 --- a/src/cmd/backend/main.go +++ b/src/cmd/backend/main.go @@ -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) diff --git a/src/repositories/centers.go b/src/repositories/centers.go index 22b1219..9f97e45 100644 --- a/src/repositories/centers.go +++ b/src/repositories/centers.go @@ -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). diff --git a/src/repositories/operators.go b/src/repositories/operators.go index ae69ac8..0b760b1 100644 --- a/src/repositories/operators.go +++ b/src/repositories/operators.go @@ -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 diff --git a/src/services/centers.go b/src/services/centers.go index 79ef016..6d2d924 100644 --- a/src/services/centers.go +++ b/src/services/centers.go @@ -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", @@ -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 diff --git a/src/services/operators.go b/src/services/operators.go index 05c18d5..4e28223 100644 --- a/src/services/operators.go +++ b/src/services/operators.go @@ -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", @@ -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