Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions core/report/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package report

import (
"context"
"time"

"github.com/goto/guardian/domain"
"github.com/goto/guardian/pkg/log"
Expand Down Expand Up @@ -64,7 +65,6 @@ func (s *Service) GetPendingApprovalsList(ctx context.Context, cfg *GetPendingAp
}

var report []*PendingApproval
var notifications []domain.Notification
for approver, appeals := range approverPendingApprovalsMap {
count := len(appeals)
report = append(report, &PendingApproval{
Expand All @@ -74,7 +74,7 @@ func (s *Service) GetPendingApprovalsList(ctx context.Context, cfg *GetPendingAp
})

s.logger.Info(ctx, "preparing notification", "pending approvals count", count, "to", approver)
notifications = append(notifications, domain.Notification{
notification := domain.Notification{
User: approver,
Message: domain.NotificationMessage{
Type: domain.NotificationTypePendingApprovalsReminder,
Expand All @@ -83,15 +83,15 @@ func (s *Service) GetPendingApprovalsList(ctx context.Context, cfg *GetPendingAp
"pending_approvals_count": count,
},
},
})
}

if !cfg.DryRun {
if errs := s.notifier.Notify(ctx, notifications); errs != nil {
for _, e := range errs {
s.logger.Error(ctx, "failed to send notifications", "error", e.Error())
}
if !cfg.DryRun {
if errs := s.notifier.Notify(ctx, []domain.Notification{notification}); errs != nil {
for _, e := range errs {
s.logger.Error(ctx, "failed to send notifications", "error", e.Error())
}
s.logger.Info(ctx, "pending approvals notifications sent")
}
s.logger.Info(ctx, "pending approvals notifications sent")
time.Sleep(time.Second)
}
}

Expand Down