refresh providers list fix
This commit is contained in:
parent
858fd6ce24
commit
70f33f1fa9
|
|
@ -9,6 +9,9 @@ INSERT INTO virtual_game_providers (
|
||||||
DELETE FROM virtual_game_providers
|
DELETE FROM virtual_game_providers
|
||||||
WHERE provider_id = $1;
|
WHERE provider_id = $1;
|
||||||
|
|
||||||
|
-- name: DeleteAllVirtualGameProviders :exec
|
||||||
|
DELETE FROM virtual_game_providers;
|
||||||
|
|
||||||
-- name: GetVirtualGameProviderByID :one
|
-- name: GetVirtualGameProviderByID :one
|
||||||
SELECT id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at
|
SELECT id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at
|
||||||
FROM virtual_game_providers
|
FROM virtual_game_providers
|
||||||
|
|
|
||||||
|
|
@ -275,6 +275,15 @@ func (q *Queries) CreateVirtualGameTransaction(ctx context.Context, arg CreateVi
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DeleteAllVirtualGameProviders = `-- name: DeleteAllVirtualGameProviders :exec
|
||||||
|
DELETE FROM virtual_game_providers
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) DeleteAllVirtualGameProviders(ctx context.Context) error {
|
||||||
|
_, err := q.db.Exec(ctx, DeleteAllVirtualGameProviders)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const DeleteVirtualGameProvider = `-- name: DeleteVirtualGameProvider :exec
|
const DeleteVirtualGameProvider = `-- name: DeleteVirtualGameProvider :exec
|
||||||
DELETE FROM virtual_game_providers
|
DELETE FROM virtual_game_providers
|
||||||
WHERE provider_id = $1
|
WHERE provider_id = $1
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ type VirtualGameRepository interface {
|
||||||
CountVirtualGameProviders(ctx context.Context) (int64, error)
|
CountVirtualGameProviders(ctx context.Context) (int64, error)
|
||||||
CreateVirtualGameProvider(ctx context.Context, arg dbgen.CreateVirtualGameProviderParams) (dbgen.VirtualGameProvider, error)
|
CreateVirtualGameProvider(ctx context.Context, arg dbgen.CreateVirtualGameProviderParams) (dbgen.VirtualGameProvider, error)
|
||||||
DeleteVirtualGameProvider(ctx context.Context, providerID string) error
|
DeleteVirtualGameProvider(ctx context.Context, providerID string) error
|
||||||
|
DeleteAllVirtualGameProviders(ctx context.Context) error
|
||||||
GetVirtualGameProviderByID(ctx context.Context, providerID string) (dbgen.VirtualGameProvider, error)
|
GetVirtualGameProviderByID(ctx context.Context, providerID string) (dbgen.VirtualGameProvider, error)
|
||||||
ListVirtualGameProviders(ctx context.Context, limit, offset int32) ([]dbgen.VirtualGameProvider, error)
|
ListVirtualGameProviders(ctx context.Context, limit, offset int32) ([]dbgen.VirtualGameProvider, error)
|
||||||
UpdateVirtualGameProviderEnabled(ctx context.Context, providerID string, enabled bool) (dbgen.VirtualGameProvider, error)
|
UpdateVirtualGameProviderEnabled(ctx context.Context, providerID string, enabled bool) (dbgen.VirtualGameProvider, error)
|
||||||
|
|
@ -93,6 +94,14 @@ func (r *VirtualGameRepo) CreateVirtualGameProvider(ctx context.Context, arg dbg
|
||||||
return r.store.queries.CreateVirtualGameProvider(ctx, arg)
|
return r.store.queries.CreateVirtualGameProvider(ctx, arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *VirtualGameRepo) RemoveVirtualGameProvider(ctx context.Context, arg dbgen.CreateVirtualGameProviderParams) (dbgen.VirtualGameProvider, error) {
|
||||||
|
return r.store.queries.CreateVirtualGameProvider(ctx, arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *VirtualGameRepo) DeleteAllVirtualGameProviders(ctx context.Context) error {
|
||||||
|
return r.store.queries.DeleteAllVirtualGameProviders(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func (r *VirtualGameRepo) DeleteVirtualGameProvider(ctx context.Context, providerID string) error {
|
func (r *VirtualGameRepo) DeleteVirtualGameProvider(ctx context.Context, providerID string) error {
|
||||||
return r.store.queries.DeleteVirtualGameProvider(ctx, providerID)
|
return r.store.queries.DeleteVirtualGameProvider(ctx, providerID)
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +112,7 @@ func (r *VirtualGameRepo) GetVirtualGameProviderByID(ctx context.Context, provid
|
||||||
|
|
||||||
func (r *VirtualGameRepo) ListVirtualGameProviders(ctx context.Context, limit, offset int32) ([]dbgen.VirtualGameProvider, error) {
|
func (r *VirtualGameRepo) ListVirtualGameProviders(ctx context.Context, limit, offset int32) ([]dbgen.VirtualGameProvider, error) {
|
||||||
args := dbgen.ListVirtualGameProvidersParams{
|
args := dbgen.ListVirtualGameProvidersParams{
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
Offset: offset,
|
Offset: offset,
|
||||||
}
|
}
|
||||||
return r.store.queries.ListVirtualGameProviders(ctx, args)
|
return r.store.queries.ListVirtualGameProviders(ctx, args)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Service) AddProviders(ctx context.Context, req domain.ProviderRequest) (*domain.ProviderResponse, error) {
|
func (s *Service) AddProviders(ctx context.Context, req domain.ProviderRequest) (*domain.ProviderResponse, error) {
|
||||||
|
// 0. Remove all existing providers first
|
||||||
|
if err := s.repo.DeleteAllVirtualGameProviders(ctx); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to clear existing providers: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// 1. Prepare signature parameters
|
// 1. Prepare signature parameters
|
||||||
sigParams := map[string]any{
|
sigParams := map[string]any{
|
||||||
"brandId": req.BrandID,
|
"brandId": req.BrandID,
|
||||||
|
|
@ -44,10 +49,9 @@ func (s *Service) AddProviders(ctx context.Context, req domain.ProviderRequest)
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := s.repo.CreateVirtualGameProvider(ctx, createParams)
|
if _, err := s.repo.CreateVirtualGameProvider(ctx, createParams); err != nil {
|
||||||
if err != nil {
|
|
||||||
// Log error but continue with other providers
|
// Log error but continue with other providers
|
||||||
return nil, err
|
return nil, fmt.Errorf("failed to add provider %s: %w", p.ProviderID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -144,8 +144,8 @@ func SetupReportandVirtualGameCronJobs(
|
||||||
period string
|
period string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
spec: "60 0 0 * * *", // 1 Minute
|
spec: "*/60 * * * * *", // Every 1 minute for testing
|
||||||
period: "1 minute",
|
period: "test",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
spec: "0 0 0 * * *", // Daily at midnight
|
spec: "0 0 0 * * *", // Daily at midnight
|
||||||
|
|
@ -183,33 +183,55 @@ func SetupReportandVirtualGameCronJobs(
|
||||||
to = firstOfMonth.Add(-time.Second)
|
to = firstOfMonth.Add(-time.Second)
|
||||||
default:
|
default:
|
||||||
log.Printf("Unknown period: %s", period)
|
log.Printf("Unknown period: %s", period)
|
||||||
return
|
// return
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Generate Reports ---
|
// --- Generate Reports (skip for test) ---
|
||||||
log.Printf("Running %s report for period %s -> %s", period, from.Format(time.RFC3339), to.Format(time.RFC3339))
|
if period != "test" {
|
||||||
if err := reportService.GenerateReport(ctx, from, to); err != nil {
|
log.Printf("Running %s report for period %s -> %s", period, from.Format(time.RFC3339), to.Format(time.RFC3339))
|
||||||
log.Printf("Error generating %s report: %v", period, err)
|
if err := reportService.GenerateReport(ctx, from, to); err != nil {
|
||||||
} else {
|
log.Printf("Error generating %s report: %v", period, err)
|
||||||
log.Printf("Successfully generated %s report", period)
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Fetch and Add Virtual Game Providers (daily only) ---
|
|
||||||
if period == "1 minute" {
|
|
||||||
log.Println("Fetching and adding virtual game providers...")
|
|
||||||
req := domain.ProviderRequest{
|
|
||||||
BrandID: os.Getenv("VELI_BRAND_ID"), // adjust to your actual brand ID
|
|
||||||
ExtraData: true,
|
|
||||||
Size: 1000, // or any default value
|
|
||||||
Page: 1, // start from first page
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := virtualGameService.AddProviders(ctx, req); err != nil {
|
|
||||||
log.Printf("Error adding virtual game providers: %v", err)
|
|
||||||
} else {
|
} else {
|
||||||
log.Println("Successfully added virtual game providers")
|
log.Printf("Successfully generated %s report", period)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Fetch and Add Virtual Game Providers (daily + test) ---
|
||||||
|
if period == "daily" || period == "test" {
|
||||||
|
log.Printf("Fetching and adding virtual game providers (%s)...", period)
|
||||||
|
|
||||||
|
brandID := os.Getenv("VELI_BRAND_ID")
|
||||||
|
if brandID == "" {
|
||||||
|
log.Println("VELI_BRAND_ID not set, skipping provider sync")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
page := 1
|
||||||
|
size := 1000
|
||||||
|
for {
|
||||||
|
req := domain.ProviderRequest{
|
||||||
|
BrandID: brandID,
|
||||||
|
ExtraData: true,
|
||||||
|
Size: int(size),
|
||||||
|
Page: int(page),
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := virtualGameService.AddProviders(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error adding virtual game providers on page %d: %v", page, err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("[%s] Successfully processed page %d: %d providers", period, page, len(res.Items))
|
||||||
|
|
||||||
|
if len(res.Items) < size {
|
||||||
|
// Last page reached
|
||||||
|
break
|
||||||
|
}
|
||||||
|
page++
|
||||||
|
}
|
||||||
|
log.Printf("[%s] Finished fetching and adding virtual game providers", period)
|
||||||
|
}
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Fatalf("Failed to schedule %s cron job: %v", period, err)
|
log.Fatalf("Failed to schedule %s cron job: %v", period, err)
|
||||||
}
|
}
|
||||||
|
|
@ -219,6 +241,8 @@ func SetupReportandVirtualGameCronJobs(
|
||||||
log.Printf("Cron jobs started. Reports will be saved to: %s", outputDir)
|
log.Printf("Cron jobs started. Reports will be saved to: %s", outputDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func ProcessBetCashback(ctx context.Context, betService *betSvc.Service) {
|
func ProcessBetCashback(ctx context.Context, betService *betSvc.Service) {
|
||||||
c := cron.New(cron.WithSeconds())
|
c := cron.New(cron.WithSeconds())
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user