mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-25 13:17:42 +00:00
some stats
This commit is contained in:
parent
771e0e221e
commit
9af3586c31
1 changed files with 15 additions and 0 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/DataDog/datadog-go/statsd"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
"github.com/sideshow/apns2"
|
"github.com/sideshow/apns2"
|
||||||
|
@ -43,6 +44,11 @@ func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, qu
|
||||||
|
|
||||||
client := apns2.NewTokenClient(token)
|
client := apns2.NewTokenClient(token)
|
||||||
|
|
||||||
|
statsd, err := statsd.New("127.0.0.1:8125")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-quit:
|
case <-quit:
|
||||||
|
@ -85,7 +91,11 @@ func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, qu
|
||||||
tokens.AccessToken, tokens.RefreshToken, now+3500, account.ID)
|
tokens.AccessToken, tokens.RefreshToken, now+3500, account.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t1 := time.Now()
|
||||||
msgs, err := rac.MessageInbox(account.LastMessageID)
|
msgs, err := rac.MessageInbox(account.LastMessageID)
|
||||||
|
t2 := time.Now()
|
||||||
|
statsd.Histogram("reddit.api.latency", t2.Sub(t1).Milliseconds())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -132,10 +142,15 @@ func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, qu
|
||||||
notification.DeviceToken = device
|
notification.DeviceToken = device
|
||||||
notification.Topic = "com.christianselig.Apollo"
|
notification.Topic = "com.christianselig.Apollo"
|
||||||
notification.Payload = payload.NewPayload().AlertTitle(msg.Subject).AlertBody(msg.Body)
|
notification.Payload = payload.NewPayload().AlertTitle(msg.Subject).AlertBody(msg.Body)
|
||||||
|
t1 := time.Now()
|
||||||
res, err := client.Push(notification)
|
res, err := client.Push(notification)
|
||||||
|
t2 := time.Now()
|
||||||
|
statsd.Histogram("apns.notification.latency", t2.Sub(t1).Milliseconds())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
statsd.Incr("apns.notification.errors", 1)
|
||||||
logger.Printf("Error sending push to %s: %s", device, err)
|
logger.Printf("Error sending push to %s: %s", device, err)
|
||||||
} else {
|
} else {
|
||||||
|
statsd.Incr("apns.notification.sent", 1)
|
||||||
logger.Printf("Push response: %v %v %v\n", res.StatusCode, res.ApnsID, res.Reason)
|
logger.Printf("Push response: %v %v %v\n", res.StatusCode, res.ApnsID, res.Reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue