Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

improve(api): ensure we do 3 attempts to add events to the queue

Carl-Gerhard Lindesvärd6ad47c8bd1b4
diff --git a/apps/api/src/controllers/event.controller.ts b/apps/api/src/controllers/event.controller.ts
index cd12497e4..ef0fde372 100644
--- a/apps/api/src/controllers/event.controller.ts
+++ b/apps/api/src/controllers/event.controller.ts
@@ -49,7 +49,7 @@ export async function postEvent(
'NX',
);
- eventsQueue.add(
+ await eventsQueue.add(
'event',
{
type: 'incomingEvent',
@@ -68,6 +68,11 @@ export async function postEvent(
},
},
{
+ attempts: 3,
+ backoff: {
+ 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
diff --git a/apps/api/src/controllers/track.controller.ts b/apps/api/src/controllers/track.controller.ts
index aa4f5b539..61345c98b 100644
--- a/apps/api/src/controllers/track.controller.ts
+++ b/apps/api/src/controllers/track.controller.ts
@@ -248,7 +248,7 @@ async function track({
'NX',
);
- eventsQueue.add(
+ await eventsQueue.add(
'event',
{
type: 'incomingEvent',
@@ -267,6 +267,11 @@ async function track({
},
},
{
+ attempts: 3,
+ backoff: {
+ 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
diff --git a/apps/worker/src/utils/session-handler.ts b/apps/worker/src/utils/session-handler.ts
index 36a2b69cc..4311c0ce4 100644
--- a/apps/worker/src/utils/session-handler.ts
+++ b/apps/worker/src/utils/session-handler.ts
@@ -27,6 +27,11 @@ export async function createSessionEnd({
{
delay: SESSION_TIMEOUT,
jobId: getSessionEndJobId(payload.projectId, payload.deviceId),
+ attempts: 3,
+ backoff: {
+ type: 'exponential',
+ delay: 200,
+ },
},
);