Files
warmbly/internal/app/consumer/risk_mark.go
T

46 lines
1.2 KiB
Go

package jobs
import (
"context"
"github.com/google/uuid"
"github.com/rs/zerolog/log"
"github.com/warmbly/warmbly/internal/models"
)
func (s *JobsService) markRiskBandFromWarmupHealth(ctx context.Context, accountID uuid.UUID, health *models.WarmupParticipantHealth) {
if s.WorkerRepo == nil {
return
}
state := models.WarmupHealthHealthy
if health != nil {
state = health.HealthState
} else if resolved, ok := s.resolveWarmupHealthState(ctx, accountID); ok {
state = resolved
}
band := models.RiskBandFromHealth(state)
if err := s.WorkerRepo.SetEmailAccountRiskBand(ctx, accountID, band); err != nil {
log.Warn().
Err(err).
Str("account_id", accountID.String()).
Str("risk_band", string(band)).
Msg("failed to update account risk band from warmup health")
}
}
func (s *JobsService) resolveWarmupHealthState(ctx context.Context, accountID uuid.UUID) (models.WarmupHealthState, bool) {
if s.WarmupRepo == nil {
return "", false
}
// The mailbox's standing, including one Warmbly Cloud reported for a
// mailbox it warms, so a local event cannot reset a cloud hold's band.
state, _, err := s.WarmupRepo.GetHealthState(ctx, accountID)
if err != nil {
return "", false
}
return state, true
}