chore(api): add option to not add new jobs

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-02-08 22:13:16 +01:00
parent 6cc3bea802
commit 2688a428d9
2 changed files with 52 additions and 46 deletions

View File

@@ -49,31 +49,34 @@ export async function postEvent(
'NX', 'NX',
); );
eventsQueue.add( // TODO: remove this
'event', if (process.env.DISABLE_ADD_JOBS === undefined) {
{ eventsQueue.add(
type: 'incomingEvent', 'event',
payload: { {
projectId, type: 'incomingEvent',
headers: getStringHeaders(request.headers), payload: {
event: { projectId,
...request.body, headers: getStringHeaders(request.headers),
timestamp: timestamp.timestamp, event: {
isTimestampFromThePast: timestamp.isTimestampFromThePast, ...request.body,
timestamp: timestamp.timestamp,
isTimestampFromThePast: timestamp.isTimestampFromThePast,
},
geo,
currentDeviceId,
previousDeviceId,
priority: locked === 'OK',
}, },
geo,
currentDeviceId,
previousDeviceId,
priority: locked === 'OK',
}, },
}, {
{ // Prioritize 'screen_view' events by setting no delay
// Prioritize 'screen_view' events by setting no delay // This ensures that session starts are created from 'screen_view' events
// This ensures that session starts are created from 'screen_view' events // rather than other events, maintaining accurate session tracking
// rather than other events, maintaining accurate session tracking delay: request.body.name === 'screen_view' ? undefined : 1000,
delay: request.body.name === 'screen_view' ? undefined : 1000, },
}, );
); }
reply.status(202).send('ok'); reply.status(202).send('ok');
} }

View File

@@ -247,31 +247,34 @@ async function track({
'NX', 'NX',
); );
eventsQueue.add( // TODO: remove this
'event', if (process.env.DISABLE_ADD_JOBS === undefined) {
{ eventsQueue.add(
type: 'incomingEvent', 'event',
payload: { {
projectId, type: 'incomingEvent',
headers, payload: {
event: { projectId,
...payload, headers,
timestamp, event: {
isTimestampFromThePast, ...payload,
timestamp,
isTimestampFromThePast,
},
geo,
currentDeviceId,
previousDeviceId,
priority: locked === 'OK',
}, },
geo,
currentDeviceId,
previousDeviceId,
priority: locked === 'OK',
}, },
}, {
{ // Prioritize 'screen_view' events by setting no delay
// Prioritize 'screen_view' events by setting no delay // This ensures that session starts are created from 'screen_view' events
// This ensures that session starts are created from 'screen_view' events // rather than other events, maintaining accurate session tracking
// rather than other events, maintaining accurate session tracking delay: payload.name === 'screen_view' ? undefined : 1000,
delay: payload.name === 'screen_view' ? undefined : 1000, },
}, );
); }
} }
async function identify({ async function identify({