Commit ef047c5c authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Ensure tournament end callbacks carry the correct end and reset times.

parent 3af959e0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
### Fixed
- Correctly calculate 'can enter' field for newly created tournaments.
- Ensure tournament reset callbacks carry the correct ID.
- Ensure tournament end callbacks carry the correct end and reset times.

## [2.9.1] - 2020-01-14
### Changed
+7 −5
Original line number Diff line number Diff line
@@ -284,15 +284,17 @@ func (ls *LocalLeaderboardScheduler) queueEndActiveElapse(t time.Time, ids []str
		return
	}

	ts := t.Unix()
	tMinusOne := time.Unix(ts-1, 0).UTC()

	// Immediately schedule the next invocation to avoid any gaps caused by time spent processing below.
	ls.Update()

	// Skip processing if there is no tournament end callback registered.
	if ls.fnTournamentEnd == nil {
		return
	}

	// Immediately schedule the next invocation to avoid any gaps caused by time spent processing below.
	ls.Update()

	ts := t.Unix()
	ls.Lock()
	if ls.lastEnd != 0 && ls.lastEnd >= ts {
		// Avoid running duplicate or delayed scheduling.
@@ -309,7 +311,7 @@ func (ls *LocalLeaderboardScheduler) queueEndActiveElapse(t time.Time, ids []str
		for _, id := range ids {
			currentId := id
			// Will block if the queue is full.
			ls.queue <- &LeaderboardSchedulerCallback{id: currentId, ts: ts}
			ls.queue <- &LeaderboardSchedulerCallback{id: currentId, ts: ts, t: tMinusOne}
		}
	}()
}
+2 −1
Original line number Diff line number Diff line
@@ -1424,7 +1424,7 @@ func (rp *RuntimeProviderLua) TournamentEnd(ctx context.Context, tournament *api

	luaCtx := NewRuntimeLuaContext(r.vm, r.luaEnv, RuntimeExecutionModeTournamentEnd, nil, 0, "", "", nil, "", "", "")

	tournamentTable := r.vm.CreateTable(0, 16)
	tournamentTable := r.vm.CreateTable(0, 17)

	tournamentTable.RawSetString("id", lua.LString(tournament.Id))
	tournamentTable.RawSetString("title", lua.LString(tournament.Title))
@@ -1439,6 +1439,7 @@ func (rp *RuntimeProviderLua) TournamentEnd(ctx context.Context, tournament *api
	tournamentTable.RawSetString("max_size", lua.LNumber(tournament.MaxSize))
	tournamentTable.RawSetString("max_num_score", lua.LNumber(tournament.MaxNumScore))
	tournamentTable.RawSetString("duration", lua.LNumber(tournament.Duration))
	tournamentTable.RawSetString("start_active", lua.LNumber(tournament.StartActive))
	tournamentTable.RawSetString("end_active", lua.LNumber(tournament.EndActive))
	tournamentTable.RawSetString("can_enter", lua.LBool(tournament.CanEnter))
	tournamentTable.RawSetString("next_reset", lua.LNumber(tournament.NextReset))