mirror of
https://github.com/christianselig/apollo-backend
synced 2024-12-24 23:35:27 +00:00
pass a shared statsd instance
This commit is contained in:
parent
d1c347b5d6
commit
989a04da3b
1 changed files with 9 additions and 8 deletions
|
@ -31,7 +31,7 @@ type application struct {
|
|||
var workers int = runtime.NumCPU() * 8
|
||||
var rate float64 = 1
|
||||
|
||||
func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, quit chan bool) {
|
||||
func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, statsd *statsd.Client, quit chan bool) {
|
||||
authKey, err := token.AuthKeyFromBytes([]byte(os.Getenv("APPLE_KEY_PKEY")))
|
||||
token := &token.Token{
|
||||
AuthKey: authKey,
|
||||
|
@ -45,11 +45,6 @@ func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, qu
|
|||
|
||||
client := apns2.NewTokenClient(token)
|
||||
|
||||
statsd, err := statsd.New("127.0.0.1:8125")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-quit:
|
||||
|
@ -131,12 +126,13 @@ func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, qu
|
|||
if err != nil {
|
||||
logger.Fatal(err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var device string
|
||||
rows.Scan(&device)
|
||||
devices = append(devices, device)
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
for _, msg := range msgs.MessageListing.Messages {
|
||||
for _, device := range devices {
|
||||
|
@ -187,12 +183,17 @@ func main() {
|
|||
|
||||
db.SetMaxOpenConns(workers)
|
||||
|
||||
statsd, err := statsd.New("127.0.0.1:8125")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// This is a very conservative value -- seen as most of the work that is done in these jobs is
|
||||
//
|
||||
runtime.GOMAXPROCS(workers)
|
||||
quitCh := make(chan bool, workers)
|
||||
for i := 0; i < workers; i++ {
|
||||
go accountWorker(i, rc, db, logger, quitCh)
|
||||
go accountWorker(i, rc, db, logger, statsd, quitCh)
|
||||
}
|
||||
|
||||
sigs := make(chan os.Signal, 1)
|
||||
|
|
Loading…
Reference in a new issue