tournament

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTournamentNotFound        = errors.New("tournament not found")
	ErrTournamentMaxSizeReached  = errors.New("tournament max size reached")
	ErrTournamentOutsideDuration = errors.New("tournament is outside active duration")
	ErrTournamentEnded           = errors.New("tournament has already ended")
)

Functions

func AddAttempt

func AddAttempt(ctx context.Context, pool *pgxpool.Pool, tournamentID, ownerID string, count int) error

AddAttempt increases max_num_score for a player in the current tournament occurrence.

func JoinTournament

func JoinTournament(ctx context.Context, pool *pgxpool.Pool, tournamentID, ownerID, username string) error

JoinTournament registers a player for the current tournament occurrence.

Types

type ClusterLeader

type ClusterLeader interface {
	TryAcquire(ctx context.Context) bool
}

ClusterLeader is a Redis SETNX leadership lease (same pattern as runtime cron lock).

type LeaderboardResetHook

type LeaderboardResetHook func(ctx context.Context, pool *pgxpool.Pool, leaderboardID string, resetUnix int64) error

LeaderboardResetHook is triggered when a regular leaderboard resets.

type ResetHook

type ResetHook func(ctx context.Context, pool *pgxpool.Pool, tournamentID string, endActive, nextReset int64) error

ResetHook is triggered when a tournament occurrence resets/expires.

type RewardHook

type RewardHook func(ctx context.Context, pool *pgxpool.Pool, tournamentID string, expiryTime time.Time, topRecords []*leaderboard.LeaderboardRecord) error

RewardHook is triggered when a tournament active window ends.

type TournamentScheduler

type TournamentScheduler struct {
	// contains filtered or unexported fields
}

TournamentScheduler manages tournament end/reset and leaderboard reset callbacks.

func NewTournamentScheduler

func NewTournamentScheduler(pool *pgxpool.Pool, rdb *redis.Client, logger *zap.Logger, hook RewardHook) *TournamentScheduler

NewTournamentScheduler creates a new scheduler.

func (*TournamentScheduler) SetLeaderboardLeaderLock

func (ts *TournamentScheduler) SetLeaderboardLeaderLock(lock ClusterLeader)

SetLeaderboardLeaderLock attaches Redis leadership for leaderboard reset ticks.

func (*TournamentScheduler) SetLeaderboardResetHook

func (ts *TournamentScheduler) SetLeaderboardResetHook(hook LeaderboardResetHook)

SetLeaderboardResetHook configures the leaderboard reset callback.

func (*TournamentScheduler) SetResetHook

func (ts *TournamentScheduler) SetResetHook(hook ResetHook)

SetResetHook configures the tournament reset callback.

func (*TournamentScheduler) SetRewardHook

func (ts *TournamentScheduler) SetRewardHook(hook RewardHook)

SetRewardHook configures the tournament end/reward callback.

func (*TournamentScheduler) SetTournamentLeaderLock

func (ts *TournamentScheduler) SetTournamentLeaderLock(lock ClusterLeader)

SetTournamentLeaderLock attaches Redis leadership for tournament end/reset ticks.

func (*TournamentScheduler) Start

func (ts *TournamentScheduler) Start(tickInterval time.Duration)

Start runs timer-based end/expiry evaluation with a callback worker queue. tickInterval is retained for compatibility; timers drive precision scheduling.

func (*TournamentScheduler) Stop

func (ts *TournamentScheduler) Stop()

Stop halts the scheduler loop.

func (*TournamentScheduler) Update

func (ts *TournamentScheduler) Update()

Update recalculates the next end-active and expiry timers from cached/DB configs.

type TournamentView

type TournamentView struct {
	*leaderboard.Leaderboard
	CanEnter    bool  `json:"can_enter"`
	StartActive int64 `json:"start_active"`
	EndActive   int64 `json:"end_active"`
	PrevReset   int64 `json:"prev_reset"`
	NextReset   int64 `json:"next_reset"`
}

TournamentView is a list/detail projection with computed active fields.

func GetTournaments

func GetTournaments(ctx context.Context, pool *pgxpool.Pool, ids []string) ([]*TournamentView, error)

GetTournaments fetches tournaments by ID.

func ListTournaments

func ListTournaments(
	ctx context.Context,
	pool *pgxpool.Pool,
	categoryStart, categoryEnd int,
	startTime, endTime time.Time,
	limit int,
	cursor string,
	activeOnly bool,
) ([]*TournamentView, string, error)

ListTournaments retrieves tournaments filterable by category, time, and active flag.

func ToView

ToView computes active-state fields for a tournament leaderboard.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL