improve(queue): how we handle incoming events and session ends

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-06-03 21:13:15 +02:00
parent 39775142e2
commit 0d58a5bf0c
13 changed files with 245 additions and 266 deletions

View File

@@ -55,15 +55,6 @@ export async function postEvent(
return;
}
const isScreenView = request.body.name === 'screen_view';
// this will ensure that we don't have multiple events creating sessions
const LOCK_DURATION = 1000;
const locked = await getLock(
`request:priority:${currentDeviceId}-${previousDeviceId}:${isScreenView ? 'screen_view' : 'other'}`,
'locked',
LOCK_DURATION,
);
await eventsQueue.add(
'event',
{
@@ -79,7 +70,6 @@ export async function postEvent(
geo,
currentDeviceId,
previousDeviceId,
priority: locked,
},
},
{
@@ -88,10 +78,6 @@ export async function postEvent(
type: 'exponential',
delay: 200,
},
// Prioritize 'screen_view' events by setting no delay
// This ensures that session starts are created from 'screen_view' events
// rather than other events, maintaining accurate session tracking
delay: isScreenView ? undefined : LOCK_DURATION - 100,
},
);