Skip to content

Commit

Permalink
fix: try waiting to subscribe events deeper
Browse files Browse the repository at this point in the history
  • Loading branch information
Geczy committed Sep 20, 2023
1 parent 13cc62e commit 6c3d434
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
12 changes: 0 additions & 12 deletions packages/twitch/events/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import { SubscribeEvents } from './SubscribeEvents.js'
import { getAccountIds } from './twitch/lib/getAccountIds.js'
import { setupSocketIO } from './utils/socketUtils.js'
import { setupWebhooks } from './utils/webhookUtils.js'

// Load every account id when booting server
getAccountIds()
.then((accountIds) => {
console.log('[TWITCHEVENTS] Retrieved accountIds', { length: accountIds.length })
SubscribeEvents(accountIds)
})
.catch((e) => {
console.log('[TWITCHEVENTS] error getting accountIds', { e })
})

setupSocketIO()
setupWebhooks()
13 changes: 11 additions & 2 deletions packages/twitch/events/src/utils/webhookUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { chatClient } from '../chatClient.js'
import { Tables } from '../db/supabase-types.js'
import { handleNewUser } from '../handleNewUser.js'
import { middleware } from '../listener.js'
import { SubscribeEvents } from '../SubscribeEvents.js'
import { getAccountIds } from '../twitch/lib/getAccountIds.js'
import { InsertPayload, UpdatePayload } from '../types.js'

export const setupWebhooks = () => {
Expand Down Expand Up @@ -112,8 +114,15 @@ export const setupWebhooks = () => {
},
)

webhookApp.listen(5010, () => {
void middleware.markAsReady()
// Why can't i use async on express listen?
// eslint-disable-next-line @typescript-eslint/no-misused-promises
webhookApp.listen(5010, async () => {
await middleware.markAsReady()

// Load every account id when booting server
const accountIds = await getAccountIds()
SubscribeEvents(accountIds)

console.log('[TWITCHEVENTS] Webhooks Listening on port 5010')
})
}

0 comments on commit 6c3d434

Please sign in to comment.