Commit 0abe3796 authored by Mo Firouz's avatar Mo Firouz
Browse files

Fix delayed first time invocation of tournament and leaderboard callbacks.

parent 2de04d10
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -8,6 +8,12 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Explicitly set cache control header in all API responses.
- Add support for CockroachDB 19.1.

### Changed
- Tournament start time can be set to past time.  

### Fixed
- Fix delayed first time invocation of tournament and leaderboard callbacks. 

## [2.5.1] - 2019-05-03
### Changed
- Storage object get operations now also return the user ID if the owner is the root user.
+7 −0
Original line number Diff line number Diff line
@@ -465,6 +465,11 @@ func TournamentRecordsHaystack(ctx context.Context, logger *zap.Logger, db *sql.

func calculateTournamentDeadlines(startTime, endTime, duration int64, resetSchedule *cronexpr.Expression, t time.Time) (int64, int64, int64) {
	if resetSchedule != nil {
		if t.Unix() < startTime {
			// if startTime is in the future, always use startTime
			t = time.Unix(startTime, 0).UTC()
		}

		schedules := resetSchedule.NextN(t, 2)
		schedule0Unix := schedules[0].UTC().Unix()
		schedule1Unix := schedules[1].UTC().Unix()
@@ -479,6 +484,8 @@ func calculateTournamentDeadlines(startTime, endTime, duration int64, resetSched
			startActiveUnix = resetSchedule.Next(time.Unix(startTime, 0).UTC()).UTC().Unix()
			endActiveUnix = startActiveUnix + duration
			expiryUnix = startActiveUnix + (schedule1Unix - schedule0Unix)
		} else if startTime > startActiveUnix {
			startActiveUnix = startTime
		}

		return startActiveUnix, endActiveUnix, expiryUnix
+1 −5
Original line number Diff line number Diff line
@@ -540,10 +540,6 @@ func (l *LocalLeaderboardCache) Remove(id string) {
func checkTournamentConfig(resetSchedule string, startTime, endTime, duration, maxSize, maxNumScore int) error {
	if startTime < 0 {
		return fmt.Errorf("tournament start time must be a unix UTC time in the future")
	} else if startTime == 0 {
		startTime = int(time.Now().UTC().Unix())
	} else if time.Now().UTC().After(time.Unix(int64(startTime), 0).UTC()) {
		return fmt.Errorf("tournament start time must be a unix UTC time in the future")
	}

	if duration <= 0 {
@@ -563,7 +559,7 @@ func checkTournamentConfig(resetSchedule string, startTime, endTime, duration, m
	}

	if (endTime > 0) && (endTime < (startTime + duration)) {
		return fmt.Errorf("tournament end time cannot be before end of first session")
		return fmt.Errorf("tournament end time cannot be before end of first session or in the past")
	}

	var cron *cronexpr.Expression