Skip to content

Commit 3c61be4

Browse files
committed
fix an issue where the batch is never clear
1 parent dcdc971 commit 3c61be4

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

packages/ws-worker/src/api/process-events.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function eventProcessor(
7373

7474
let activeBatch: string | null = null;
7575
let batch: any = [];
76-
let batchTimeout: NodeJS.Timeout;
76+
let batchTimeout: NodeJS.Timeout | null = null;
7777
let didFinish = false;
7878
let timeoutHandle: NodeJS.Timeout;
7979

@@ -104,7 +104,9 @@ export function eventProcessor(
104104
};
105105

106106
const sendBatch = async (name: string) => {
107-
clearTimeout(batchTimeout);
107+
clearTimeout(batchTimeout!);
108+
batchTimeout = null;
109+
108110
// first clear the batch
109111
activeBatch = null;
110112
await send(name, batch, batch.length);
@@ -116,7 +118,9 @@ export function eventProcessor(
116118
const start = Date.now();
117119
// @ts-ignore
118120
const lightningEvent = eventMap[name] ?? name;
121+
console.log('!! calling ', name);
119122
await callbacks[name](context, payload);
123+
console.log('!! finished ', name);
120124
if (batchSize) {
121125
logger.info(
122126
`${planId} :: sent ${lightningEvent} (${batchSize}):: OK :: ${
@@ -140,6 +144,7 @@ export function eventProcessor(
140144

141145
const process = async (name: string, event: any) => {
142146
// TODO this actually shouldn't be here - should be done separately
147+
console.log('<<<<<<<< ', name);
143148
if (name !== 'workflow-log') {
144149
Sentry.addBreadcrumb({
145150
category: 'event',
@@ -196,9 +201,11 @@ export function eventProcessor(
196201
};
197202

198203
const enqueue = (name: string, event: any) => {
204+
console.log('>>>>> ', name);
199205
queue.push({ name, event });
200206

201207
if (queue.length == 1) {
208+
// if an event is still in flight, will this cause a duplicate?
202209
next();
203210
}
204211
};

0 commit comments

Comments
 (0)