mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-22 03:37:43 +00:00
address an edge case where threads without comments will never stop
This commit is contained in:
parent
c9877879da
commit
2352e146c3
1 changed files with 6 additions and 14 deletions
|
@ -121,15 +121,13 @@ type liveActivitiesConsumer struct {
|
|||
*liveActivitiesWorker
|
||||
tag int
|
||||
|
||||
apnsSandbox *apns2.Client
|
||||
apnsProduction *apns2.Client
|
||||
apns *apns2.Client
|
||||
}
|
||||
|
||||
func NewLiveActivitiesConsumer(law *liveActivitiesWorker, tag int) *liveActivitiesConsumer {
|
||||
return &liveActivitiesConsumer{
|
||||
law,
|
||||
tag,
|
||||
apns2.NewTokenClient(law.apns),
|
||||
apns2.NewTokenClient(law.apns).Production(),
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +221,7 @@ func (lac *liveActivitiesConsumer) Consume(delivery rmq.Delivery) {
|
|||
return
|
||||
}
|
||||
|
||||
if len(tr.Children) == 0 {
|
||||
if len(tr.Children) == 0 && la.ExpiresAt.After(now) {
|
||||
lac.logger.Debug("no comments found", zap.String("live_activity#apns_token", at))
|
||||
return
|
||||
}
|
||||
|
@ -262,7 +260,7 @@ func (lac *liveActivitiesConsumer) Consume(delivery rmq.Delivery) {
|
|||
PostScore: tr.Post.Score,
|
||||
}
|
||||
|
||||
if len(candidates) >= 1 {
|
||||
if len(candidates) > 0 {
|
||||
comment := candidates[0]
|
||||
|
||||
din.CommentID = comment.ID
|
||||
|
@ -277,14 +275,13 @@ func (lac *liveActivitiesConsumer) Consume(delivery rmq.Delivery) {
|
|||
ev = "end"
|
||||
}
|
||||
|
||||
pl := map[string]interface{}{
|
||||
bb, _ := json.Marshal(map[string]interface{}{
|
||||
"aps": map[string]interface{}{
|
||||
"timestamp": time.Now().Unix(),
|
||||
"event": ev,
|
||||
"content-state": din,
|
||||
},
|
||||
}
|
||||
bb, _ := json.Marshal(pl)
|
||||
})
|
||||
|
||||
notification := &apns2.Notification{
|
||||
DeviceToken: la.APNSToken,
|
||||
|
@ -293,12 +290,7 @@ func (lac *liveActivitiesConsumer) Consume(delivery rmq.Delivery) {
|
|||
Payload: bb,
|
||||
}
|
||||
|
||||
client := lac.apnsProduction
|
||||
/*if la.Sandbox {
|
||||
client = lac.apnsSandbox
|
||||
}*/
|
||||
|
||||
res, err := client.PushWithContext(ctx, notification)
|
||||
res, err := lac.apns.PushWithContext(ctx, notification)
|
||||
if err != nil {
|
||||
_ = lac.statsd.Incr("apns.live_activities.errors", []string{}, 1)
|
||||
lac.logger.Error("failed to send notification",
|
||||
|
|
Loading…
Reference in a new issue