feature(api,worker): Override default timestamp with a date from the past (#76)
* feature(worker,api): refactor incoming events and support custom timestamps from the past * fix(queue): add retry logic to events queue * fix(worker): remove properties when merging server events
This commit is contained in:
committed by
GitHub
parent
c4a2ea4858
commit
4fe338c628
@@ -7,7 +7,7 @@ import { eventsQueue } from '@openpanel/queue';
|
||||
import { getRedisCache } from '@openpanel/redis';
|
||||
import type { PostEventPayload } from '@openpanel/sdk';
|
||||
|
||||
import { getStringHeaders } from './track.controller';
|
||||
import { getStringHeaders, getTimestamp } from './track.controller';
|
||||
|
||||
export async function postEvent(
|
||||
request: FastifyRequest<{
|
||||
@@ -15,6 +15,7 @@ export async function postEvent(
|
||||
}>,
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const timestamp = getTimestamp(request.timestamp, request.body);
|
||||
const ip = getClientIp(request)!;
|
||||
const ua = request.headers['user-agent']!;
|
||||
const projectId = request.client?.projectId;
|
||||
@@ -57,10 +58,8 @@ export async function postEvent(
|
||||
headers: getStringHeaders(request.headers),
|
||||
event: {
|
||||
...request.body,
|
||||
// Dont rely on the client for the timestamp
|
||||
timestamp: request.timestamp
|
||||
? new Date(request.timestamp).toISOString()
|
||||
: new Date().toISOString(),
|
||||
timestamp: timestamp.timestamp,
|
||||
isTimestampFromThePast: timestamp.isTimestampFromThePast,
|
||||
},
|
||||
geo,
|
||||
currentDeviceId,
|
||||
|
||||
Reference in New Issue
Block a user