Skip to content

Commit

Permalink
Issue #121 (#127)
Browse files Browse the repository at this point in the history
ADD:
  - reaper/reaper.go:StartReapingScheduler() Now handles adding whitelisted
    torrents to the Redis tracker every minute.

REMOVE:
  - main.go:Init() No longer handles adding whitelisted torrents.
  • Loading branch information
Ian Clark committed May 7, 2016
1 parent b437a82 commit 17719f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
18 changes: 1 addition & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,10 @@ func Init() {
}
db.InitDB(dbConn)

c := server.OpenClient()
_, err = c.Ping().Result()
if err != nil {
panic("No Redis instance detected. If deploying without Docker, install redis-server")
}

infoHash := new(string)
name := new(string)
addedBy := new(string)
dateAdded := new(int64)

x, err := db.GetWhitelistedTorrents()
for x.Next() {
x.Scan(infoHash, name, addedBy, dateAdded)
server.CreateNewTorrentKey(c, *infoHash)
}
go reaper.StartReapingScheduler(1 * time.Minute)
}

func main() {
Init()
go reaper.StartReapingScheduler(5 * time.Minute)
server.RunServer()
}
21 changes: 21 additions & 0 deletions reaper/reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package reaper
import (
"fmt"
"gopkg.in/redis.v3"
"github.com/GrappigPanda/notorious/database"
"github.com/GrappigPanda/notorious/server"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -69,6 +71,25 @@ func StartReapingScheduler(waitTime time.Duration) {
reapedPeers := 0
go func() {
for {
// Handle any other cleanup or Notorious-related functions
c := server.OpenClient()
_, err := c.Ping().Result()
if err != nil {
panic("No Redis instance detected. If deploying without Docker, install redis-server")
}

infoHash := new(string)
name := new(string)
addedBy := new(string)
dateAdded := new(int64)

x, err := db.GetWhitelistedTorrents()
for x.Next() {
x.Scan(infoHash, name, addedBy, dateAdded)
server.CreateNewTorrentKey(c, *infoHash)
}

// Start the actual peer reaper.
time.Sleep(waitTime)
fmt.Println("Starting peer reaper")
reapedPeers += reapPeers()
Expand Down

0 comments on commit 17719f2

Please # to comment.