Skip to content

Commit f663eca

Browse files
authored
Trigger discord integration checks in 3 chunks (#1849)
1 parent 6ae836e commit f663eca

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

backend/src/serverless/integrations/services/integrationTickProcessor.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,20 @@ export class IntegrationTickProcessor extends LoggerBase {
207207
integration.id,
208208
)
209209
if (!existingRun) {
210-
const rand = Math.random()
211-
// 50% chance to delay the triggering of new integration checks for Discord integrations
212-
if (newIntService.type === IntegrationType.DISCORD && rand > 0.5) {
213-
// Delay the triggering of new integration checks for Discord integrations
214-
const delay = 30 * 60 * 1000 // 30 minutes in milliseconds
210+
const CHUNKS = 3 // Define the number of chunks
211+
const DELAY_BETWEEN_CHUNKS = 30 * 60 * 1000 // Define the delay between chunks in milliseconds
212+
const rand = Math.random() * CHUNKS
213+
const chunkIndex = Math.min(Math.floor(rand), CHUNKS - 1)
214+
const delay = chunkIndex * DELAY_BETWEEN_CHUNKS
215+
216+
// Divide integrations into chunks for Discord
217+
if (newIntService.type === IntegrationType.DISCORD) {
215218
setTimeout(async () => {
216219
logger.info(
217220
{ integrationId: integration.id },
218-
'Triggering new delayed integration check for Discord!',
221+
`Triggering new delayed integration check for Discord in ${
222+
delay / 60 / 1000
223+
} minutes!`,
219224
)
220225
await emitter.triggerIntegrationRun(
221226
integration.tenantId,

0 commit comments

Comments
 (0)