mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-24 20:57:43 +00:00
release transaction before sleeping in worker
This commit is contained in:
parent
c346b728fc
commit
725ad8bf93
1 changed files with 6 additions and 6 deletions
|
@ -29,7 +29,7 @@ type application struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var workers int = runtime.NumCPU() * 4
|
var workers int = runtime.NumCPU() * 4
|
||||||
var rate float64 = 1
|
var rate float64 = 0.1
|
||||||
|
|
||||||
func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, statsd *statsd.Client, 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")))
|
authKey, err := token.AuthKeyFromBytes([]byte(os.Getenv("APPLE_KEY_PKEY")))
|
||||||
|
@ -72,8 +72,8 @@ func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, st
|
||||||
err = tx.QueryRow(query, args...).Scan(&account.ID, &account.Username, &account.AccessToken, &account.RefreshToken, &account.ExpiresAt, &account.LastMessageID, &account.LastCheckedAt)
|
err = tx.QueryRow(query, args...).Scan(&account.ID, &account.Username, &account.AccessToken, &account.RefreshToken, &account.ExpiresAt, &account.LastMessageID, &account.LastCheckedAt)
|
||||||
|
|
||||||
if account.ID == 0 {
|
if account.ID == 0 {
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,12 +148,12 @@ func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, st
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
res, err := client.Push(notification)
|
res, err := client.Push(notification)
|
||||||
t2 := time.Now()
|
t2 := time.Now()
|
||||||
statsd.Histogram("apns.notification.latency", float64(t2.Sub(t1).Milliseconds()), []string{}, rate)
|
statsd.Histogram("apns.notification.latency", float64(t2.Sub(t1).Milliseconds()), []string{}, float64(1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
statsd.Incr("apns.notification.errors", []string{}, rate)
|
statsd.Incr("apns.notification.errors", []string{}, float64(1))
|
||||||
logger.Printf("apns error account=%s token=%s err=%s status=%d reason=%q", account.Username, device, err, res.StatusCode, res.Reason)
|
logger.Printf("apns error account=%s token=%s err=%s status=%d reason=%q", account.Username, device.APNSToken, err, res.StatusCode, res.Reason)
|
||||||
} else {
|
} else {
|
||||||
statsd.Incr("apns.notification.sent", []string{}, rate)
|
statsd.Incr("apns.notification.sent", []string{}, float64(1))
|
||||||
logger.Printf("apns success account=%s token=%s", account.Username, device.APNSToken)
|
logger.Printf("apns success account=%s token=%s", account.Username, device.APNSToken)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue