Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticker update #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions advent-of-code.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
// User Agent used for requests
const userAgent = "github.com/Alextopher/aocbot"

var ticker *time.Ticker

// AdventOfCode is an Advent of Code API client
type AdventOfCode struct {
sync.RWMutex
Expand All @@ -36,6 +38,7 @@ func NewAdventOfCode(sessionCookie string, year string, id string) *AdventOfCode
func (aoc *AdventOfCode) GetLeaderboard() *Leaderboard {
if time.Since(aoc.lastUpdated) > 15*time.Minute {
aoc.UpdateLeaderboard()
ticker.Reset(15 * time.Minute)
}

aoc.RLock()
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func main() {
// Every 15 minutes, sync the bot with the Advent of Code API
bot.Sync()

// Ticker gets initialized
ticker := time.NewTicker(15 * time.Minute)
for {
<-ticker.C
Expand Down
Loading