From 8c47590b9951517332d006dd6e4150707fb3f389 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Mon, 30 May 2022 19:08:09 +0300 Subject: [PATCH] Debugging twitch --- src/twitch/rest.go | 2 ++ src/twitch/twitch.go | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/twitch/rest.go b/src/twitch/rest.go index 4284af20..1c1722de 100644 --- a/src/twitch/rest.go +++ b/src/twitch/rest.go @@ -134,6 +134,8 @@ func getStreamStatus(ctx context.Context, twitchIDs []string) ([]streamStatus, e if err != nil { return nil, oops.New(err, "failed to read response body while processing stream statuses") } + log := logging.ExtractLogger(ctx) + log.Debug().Str("getStreamStatus response", string(body)).Msg("Got getStreamStatus response") var streamResponse twitchResponse err = json.Unmarshal(body, &streamResponse) diff --git a/src/twitch/twitch.go b/src/twitch/twitch.go index a65c8aca..205c2ee0 100644 --- a/src/twitch/twitch.go +++ b/src/twitch/twitch.go @@ -99,13 +99,13 @@ func MonitorTwitchSubscriptions(ctx context.Context, dbConn *pgxpool.Pool) jobs. var timer *time.Timer t := time.AfterFunc(3*time.Minute, func() { expiredTimers <- timer - processEventSubNotification(ctx, dbConn, ¬ification) + processEventSubNotification(ctx, dbConn, ¬ification, true) }) timer = t timers = append(timers, t) // NOTE(asaf): We also run this immediately. Since we get the category in the notification // we could show the stream as online if it's the right category. - processEventSubNotification(ctx, dbConn, ¬ification) + processEventSubNotification(ctx, dbConn, ¬ification, false) } } } @@ -417,7 +417,7 @@ func notifyDiscordOfLiveStream(ctx context.Context, dbConn db.ConnOrTx) error { return nil } -func processEventSubNotification(ctx context.Context, dbConn db.ConnOrTx, notification *twitchNotification) { +func processEventSubNotification(ctx context.Context, dbConn db.ConnOrTx, notification *twitchNotification, delayed bool) { log := logging.ExtractLogger(ctx) log.Debug().Interface("Notification", notification).Msg("Processing twitch notification") if notification.Type == notificationTypeNone { @@ -444,7 +444,7 @@ func processEventSubNotification(ctx context.Context, dbConn db.ConnOrTx, notifi } for _, streamer := range allStreamers { if streamer.TwitchLogin == result[0].TwitchLogin { - if result[0].Live == notification.Status.Live { + if delayed || (result[0].Live == notification.Status.Live) { status = result[0] } else { status = notification.Status