batching events
This commit is contained in:
committed by
Carl-Gerhard Lindesvärd
parent
244aa3b0d3
commit
5e225b7ae6
@@ -22,8 +22,7 @@ export interface EventsQueuePayloadIncomingEvent {
|
||||
};
|
||||
currentDeviceId: string;
|
||||
previousDeviceId: string;
|
||||
currentDeviceIdDeprecated: string;
|
||||
previousDeviceIdDeprecated: string;
|
||||
priority: boolean;
|
||||
};
|
||||
}
|
||||
export interface EventsQueuePayloadCreateEvent {
|
||||
@@ -32,17 +31,36 @@ export interface EventsQueuePayloadCreateEvent {
|
||||
}
|
||||
export interface EventsQueuePayloadCreateSessionEnd {
|
||||
type: 'createSessionEnd';
|
||||
payload: Pick<IServiceCreateEventPayload, 'deviceId'>;
|
||||
payload: Pick<
|
||||
IServiceCreateEventPayload,
|
||||
'deviceId' | 'sessionId' | 'profileId'
|
||||
>;
|
||||
}
|
||||
|
||||
// TODO: Rename `EventsQueuePayloadCreateSessionEnd`
|
||||
export type SessionsQueuePayload = EventsQueuePayloadCreateSessionEnd;
|
||||
|
||||
export type EventsQueuePayload =
|
||||
| EventsQueuePayloadCreateEvent
|
||||
| EventsQueuePayloadCreateSessionEnd
|
||||
| EventsQueuePayloadIncomingEvent;
|
||||
|
||||
export interface CronQueuePayload {
|
||||
export type CronQueuePayloadSalt = {
|
||||
type: 'salt';
|
||||
payload: undefined;
|
||||
}
|
||||
};
|
||||
export type CronQueuePayloadFlushEvents = {
|
||||
type: 'flushEvents';
|
||||
payload: undefined;
|
||||
};
|
||||
export type CronQueuePayloadFlushProfiles = {
|
||||
type: 'flushProfiles';
|
||||
payload: undefined;
|
||||
};
|
||||
export type CronQueuePayload =
|
||||
| CronQueuePayloadSalt
|
||||
| CronQueuePayloadFlushEvents
|
||||
| CronQueuePayloadFlushProfiles;
|
||||
|
||||
export const eventsQueue = new Queue<EventsQueuePayload>('events', {
|
||||
connection,
|
||||
@@ -51,6 +69,13 @@ export const eventsQueue = new Queue<EventsQueuePayload>('events', {
|
||||
},
|
||||
});
|
||||
|
||||
export const sessionsQueue = new Queue<SessionsQueuePayload>('sessions', {
|
||||
connection,
|
||||
defaultJobOptions: {
|
||||
removeOnComplete: 10,
|
||||
},
|
||||
});
|
||||
|
||||
export const cronQueue = new Queue<CronQueuePayload>('cron', {
|
||||
connection,
|
||||
defaultJobOptions: {
|
||||
|
||||
@@ -24,7 +24,7 @@ export async function findJobByPrefix<T>(
|
||||
async function getJob(index: number) {
|
||||
if (index >= filtered.length) return null;
|
||||
|
||||
const key = filtered[index]?.replace(/^bull:events:/, '');
|
||||
const key = filtered[index]?.replace(/^bull:(\w+):/, '');
|
||||
// return new Promise((resolve) => )
|
||||
if (key) {
|
||||
const job = await queue.getJob(key);
|
||||
|
||||
Reference in New Issue
Block a user