fix: minor issues

This commit is contained in:
Samuel Tariku 2025-09-24 21:03:56 +03:00
parent a2d75cf114
commit 927eb887ce
4 changed files with 139 additions and 69 deletions

View File

@ -184,7 +184,68 @@ func (s *Service) SendErrorStatusNotification(ctx context.Context, betID int64,
return nil return nil
} }
func (s *Service) SendAdminAlertNotification(ctx context.Context, betID int64, status domain.OutcomeStatus, extra string, companyID int64) error { func (s *Service) SendAdminErrorNotification(ctx context.Context, betID int64, status domain.OutcomeStatus, extra string, companyID int64) error {
var headline string
var message string
switch status {
case domain.OUTCOME_STATUS_ERROR, domain.OUTCOME_STATUS_PENDING:
headline = fmt.Sprintf("Processing Error for Bet #%v", betID)
message = "A processing error occurred with this bet. Please review and take corrective action."
default:
return fmt.Errorf("unsupported status: %v", status)
}
super_admin_users, _, err := s.userSvc.GetAllUsers(ctx, domain.UserFilter{
Role: string(domain.RoleSuperAdmin),
})
if err != nil {
s.mongoLogger.Error("failed to get super_admin recipients",
zap.Error(err),
zap.Time("timestamp", time.Now()),
)
return err
}
admin_users, _, err := s.userSvc.GetAllUsers(ctx, domain.UserFilter{
Role: string(domain.RoleAdmin),
CompanyID: domain.ValidInt64{
Value: companyID,
Valid: true,
},
})
if err != nil {
s.mongoLogger.Error("failed to get admin recipients",
zap.Error(err),
zap.Time("timestamp", time.Now()),
)
return err
}
users := append(super_admin_users, admin_users...)
for _, user := range users {
for _, channel := range []domain.DeliveryChannel{
domain.DeliveryChannelInApp,
domain.DeliveryChannelEmail,
} {
n := newBetResultNotification(user.ID, domain.NotificationLevelError, channel, headline, message, map[string]any{
"status": status,
"more": extra,
})
if err := s.notificationSvc.SendNotification(ctx, n); err != nil {
return err
}
}
}
return nil
}
func (s *Service) SendAdminLargeNotification(ctx context.Context, betID int64, status domain.OutcomeStatus, extra string, companyID int64) error {
var headline string var headline string
var message string var message string

View File

@ -870,7 +870,7 @@ func (s *Service) UpdateStatus(ctx context.Context, betId int64, status domain.O
} }
if status == domain.OUTCOME_STATUS_ERROR || status == domain.OUTCOME_STATUS_PENDING { if status == domain.OUTCOME_STATUS_ERROR || status == domain.OUTCOME_STATUS_PENDING {
if err := s.SendAdminAlertNotification(ctx, betId, status, "", bet.CompanyID); err != nil { if err := s.SendAdminErrorNotification(ctx, betId, status, "", bet.CompanyID); err != nil {
updateLogger.Error("failed to send admin notification", zap.Error(err)) updateLogger.Error("failed to send admin notification", zap.Error(err))
return err return err
} }

View File

@ -250,18 +250,27 @@ func (s *Service) FetchAndStoreAllVirtualGames(ctx context.Context, req domain.P
// --- Save to DB --- // --- Save to DB ---
_, err = s.repo.CreateVirtualGame(ctx, dbgen.CreateVirtualGameParams{ _, err = s.repo.CreateVirtualGame(ctx, dbgen.CreateVirtualGameParams{
GameID: fmt.Sprintf("%d", g.ID), //The id here needs to be clean for me to access GameID: fmt.Sprintf("%d", g.ID), //The id here needs to be clean for me to access
ProviderID: "popok", ProviderID: "popok",
Name: g.GameName, Name: g.GameName,
Bets: betsNumeric, Bets: betsNumeric,
Thumbnail: pgtype.Text{ Thumbnail: pgtype.Text{
String: g.Thumbnail, String: g.Thumbnail,
Valid: g.Thumbnail != "", Valid: g.Thumbnail != "",
}, },
Status: pgtype.Int4{ Status: pgtype.Int4{
Int32: int32(g.Status), Int32: int32(g.Status),
Valid: true, Valid: true,
}, },
HasDemo: pgtype.Bool{
Bool: true,
Valid: true,
},
Category: pgtype.Text{
String: "Crash",
Valid: true,
},
}) })
if err != nil { if err != nil {

View File

@ -26,71 +26,71 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S
spec string spec string
task func() task func()
}{ }{
{ // {
spec: "0 0 * * * *", // Every 1 hour // spec: "0 0 * * * *", // Every 1 hour
task: func() { // task: func() {
mongoLogger.Info("Began fetching upcoming events cron task") // mongoLogger.Info("Began fetching upcoming events cron task")
if err := eventService.FetchUpcomingEvents(context.Background()); err != nil { // if err := eventService.FetchUpcomingEvents(context.Background()); err != nil {
mongoLogger.Error("Failed to fetch upcoming events", // mongoLogger.Error("Failed to fetch upcoming events",
zap.Error(err), // zap.Error(err),
) // )
} else { // } else {
mongoLogger.Info("Completed fetching upcoming events without errors") // mongoLogger.Info("Completed fetching upcoming events without errors")
} // }
}, // },
}, // },
{ // {
spec: "0 0 * * * *", // Every 1 hour (since its takes that long to fetch all the events) // spec: "0 0 * * * *", // Every 1 hour (since its takes that long to fetch all the events)
task: func() { // task: func() {
mongoLogger.Info("Began fetching non live odds cron task") // mongoLogger.Info("Began fetching non live odds cron task")
if err := oddsService.FetchNonLiveOdds(context.Background()); err != nil { // if err := oddsService.FetchNonLiveOdds(context.Background()); err != nil {
mongoLogger.Error("Failed to fetch non live odds", // mongoLogger.Error("Failed to fetch non live odds",
zap.Error(err), // zap.Error(err),
) // )
} else { // } else {
mongoLogger.Info("Completed fetching non live odds without errors") // mongoLogger.Info("Completed fetching non live odds without errors")
} // }
}, // },
}, // },
{ // {
spec: "0 */5 * * * *", // Every 5 Minutes // spec: "0 */5 * * * *", // Every 5 Minutes
task: func() { // task: func() {
mongoLogger.Info("Began update all expired events status cron task") // mongoLogger.Info("Began update all expired events status cron task")
if _, err := resultService.CheckAndUpdateExpiredEvents(context.Background()); err != nil { // if _, err := resultService.CheckAndUpdateExpiredEvents(context.Background()); err != nil {
mongoLogger.Error("Failed to update expired events status", // mongoLogger.Error("Failed to update expired events status",
zap.Error(err), // zap.Error(err),
) // )
} else { // } else {
mongoLogger.Info("Completed expired events without errors") // mongoLogger.Info("Completed expired events without errors")
} // }
}, // },
}, // },
{ // {
spec: "0 */15 * * * *", // Every 15 Minutes // spec: "0 */15 * * * *", // Every 15 Minutes
task: func() { // task: func() {
mongoLogger.Info("Began fetching results for upcoming events cron task") // mongoLogger.Info("Began fetching results for upcoming events cron task")
if err := resultService.FetchAndProcessResults(context.Background()); err != nil { // if err := resultService.FetchAndProcessResults(context.Background()); err != nil {
mongoLogger.Error("Failed to process result", // mongoLogger.Error("Failed to process result",
zap.Error(err), // zap.Error(err),
) // )
} else { // } else {
mongoLogger.Info("Completed processing all event result outcomes without errors") // mongoLogger.Info("Completed processing all event result outcomes without errors")
} // }
}, // },
}, // },
{ // {
spec: "0 0 0 * * *", // Every Day // spec: "0 0 0 * * *", // Every Day
task: func() { // task: func() {
mongoLogger.Info("Began Send daily result notification cron task") // mongoLogger.Info("Began Send daily result notification cron task")
if err := resultService.CheckAndSendResultNotifications(context.Background(), time.Now().Add(-24*time.Hour)); err != nil { // if err := resultService.CheckAndSendResultNotifications(context.Background(), time.Now().Add(-24*time.Hour)); err != nil {
mongoLogger.Error("Failed to process result", // mongoLogger.Error("Failed to process result",
zap.Error(err), // zap.Error(err),
) // )
} else { // } else {
mongoLogger.Info("Completed sending daily result notification without errors") // mongoLogger.Info("Completed sending daily result notification without errors")
} // }
}, // },
}, // },
} }
for _, job := range schedule { for _, job := range schedule {