Skip to content

Commit

Permalink
fix(eventsub): retry deadline subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont committed May 31, 2024
1 parent 1a7e8ee commit a5fe059
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 38 deletions.
43 changes: 43 additions & 0 deletions apps/eventsub/internal/manager/condition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package manager

import (
model "github.com/satont/twir/libs/gomodels"
)

func getTypeCondition(
t model.EventsubConditionType,
topic,
channelID,
botId string,
) map[string]string {
switch t {
case model.EventsubConditionTypeBroadcasterUserID:
return map[string]string{
"broadcaster_user_id": channelID,
}
case model.EventsubConditionTypeUserID:
return map[string]string{
"user_id": channelID,
}
case model.EventsubConditionTypeBroadcasterWithUserID:
data := map[string]string{
"broadcaster_user_id": channelID,
"user_id": botId,
}
if topic == "channel.follow" {
data["user_id"] = channelID
}
return data
case model.EventsubConditionTypeBroadcasterWithModeratorID:
return map[string]string{
"broadcaster_user_id": channelID,
"moderator_user_id": botId,
}
case model.EventsubConditionTypeToBroadcasterID:
return map[string]string{
"to_broadcaster_user_id": channelID,
}
default:
return nil
}
}
38 changes: 0 additions & 38 deletions apps/eventsub/internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,44 +186,6 @@ func NewManager(opts Opts) (*Manager, error) {
return manager, nil
}

func getTypeCondition(
t model.EventsubConditionType,
topic,
channelID,
botId string,
) map[string]string {
switch t {
case model.EventsubConditionTypeBroadcasterUserID:
return map[string]string{
"broadcaster_user_id": channelID,
}
case model.EventsubConditionTypeUserID:
return map[string]string{
"user_id": channelID,
}
case model.EventsubConditionTypeBroadcasterWithUserID:
data := map[string]string{
"broadcaster_user_id": channelID,
"user_id": botId,
}
if topic == "channel.follow" {
data["user_id"] = channelID
}
return data
case model.EventsubConditionTypeBroadcasterWithModeratorID:
return map[string]string{
"broadcaster_user_id": channelID,
"moderator_user_id": botId,
}
case model.EventsubConditionTypeToBroadcasterID:
return map[string]string{
"to_broadcaster_user_id": channelID,
}
default:
return nil
}
}

var statusesForSkip = []string{
"enabled",
"webhook_callback_verification_pending",
Expand Down
5 changes: 5 additions & 0 deletions apps/eventsub/internal/manager/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package manager
import (
"context"
"errors"
"strings"
"time"

"github.com/avast/retry-go/v4"
Expand Down Expand Up @@ -34,6 +35,10 @@ func (c *Manager) SubscribeWithLimits(
return true
}

if strings.Contains(err.Error(), "context deadline exceeded") {
return true
}

return false
},
),
Expand Down

0 comments on commit a5fe059

Please sign in to comment.