Skip to content

Commit

Permalink
fix(eventsub): insert subscription in any case in db
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont committed May 31, 2024
1 parent 6a9ea82 commit 7cfae27
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions apps/eventsub/internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,29 +264,27 @@ func (c *Manager) SubscribeToNeededEvents(
return
}

if (status != nil && len(status.Data) > 0) || (casterErr != nil && casterErr.Status == 409) {
subStatus := "enabled"
subId := uuid.New()
if status != nil && len(status.Data) > 0 {
subStatus = status.Data[0].Status
subId = uuid.MustParse(status.Data[0].ID)
}

if err := c.gorm.Create(
&model.EventsubSubscription{
ID: subId,
TopicID: topic.ID,
UserID: broadcasterId,
Status: subStatus,
Version: topic.Version,
CallbackUrl: c.tunnel.GetAddr(),
},
).Error; err != nil {
c.logger.Error("failed to create subscription", slog.Any("err", err))
}
subStatus := "unknown"
subId := uuid.New()
if status != nil && len(status.Data) > 0 {
subStatus = status.Data[0].Status
subId = uuid.MustParse(status.Data[0].ID)
}

newSubsCount.Inc()
if err := c.gorm.Create(
&model.EventsubSubscription{
ID: subId,
TopicID: topic.ID,
UserID: broadcasterId,
Status: subStatus,
Version: topic.Version,
CallbackUrl: c.tunnel.GetAddr(),
},
).Error; err != nil {
c.logger.Error("failed to create subscription", slog.Any("err", err))
}

newSubsCount.Inc()
}()
}

Expand Down

0 comments on commit 7cfae27

Please sign in to comment.