Skip to content

Commit be02fe6

Browse files
committed
Improved logs and removed events from test
1 parent 72cbabe commit be02fe6

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

packages/redis-worker/src/queue.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,16 @@ export class SimpleQueue<TMessageCatalog extends MessageCatalogSchema> {
208208
async ack(id: string, deduplicationKey?: string): Promise<void> {
209209
try {
210210
const result = await this.redis.ackItem(`queue`, `items`, id, deduplicationKey ?? "");
211-
if (result === 0) {
212-
this.logger.error(`SimpleQueue ${this.name}.ack(): ack operation returned 0`, {
213-
queue: this.name,
214-
id,
215-
deduplicationKey,
216-
});
211+
if (result !== 1) {
212+
this.logger.debug(
213+
`SimpleQueue ${this.name}.ack(): ack operation returned ${result}. This means it was not removed from the queue.`,
214+
{
215+
queue: this.name,
216+
id,
217+
deduplicationKey,
218+
result,
219+
}
220+
);
217221
}
218222
} catch (e) {
219223
this.logger.error(`SimpleQueue ${this.name}.ack(): error acknowledging item`, {

packages/redis-worker/src/worker.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ describe("Worker", () => {
324324
const processedPayloads: string[] = [];
325325
const jobStarted: string[] = [];
326326
let firstJobCompleted = false;
327-
const events: string[] = [];
328327

329328
const worker = new Worker({
330329
name: "test-worker",
@@ -344,7 +343,6 @@ describe("Worker", () => {
344343
testJob: async ({ payload }) => {
345344
// Record when the job starts processing
346345
jobStarted.push(payload.value);
347-
events.push(`Job started: ${payload.value}`);
348346

349347
if (payload.value === "first-attempt") {
350348
// First job takes a long time to process
@@ -354,7 +352,6 @@ describe("Worker", () => {
354352

355353
// Record when the job completes
356354
processedPayloads.push(payload.value);
357-
events.push(`Job completed: ${payload.value}`);
358355
},
359356
},
360357
concurrency: {
@@ -373,11 +370,9 @@ describe("Worker", () => {
373370
job: "testJob",
374371
payload: { value: "first-attempt" },
375372
});
376-
events.push("First job enqueued");
377373

378374
// Verify initial queue size
379375
const size1 = await worker.queue.size({ includeFuture: true });
380-
events.push(`Queue size after first enqueue: ${size1}`);
381376
expect(size1).toBe(1);
382377

383378
// Wait until we know the first job has started processing
@@ -393,37 +388,27 @@ describe("Worker", () => {
393388
payload: { value: "second-attempt" },
394389
availableAt: new Date(Date.now() + 1500),
395390
});
396-
events.push("Second job enqueued with future availableAt");
397391

398392
// Verify queue size after second enqueue
399393
const size2 = await worker.queue.size({ includeFuture: true });
400394
const size2Present = await worker.queue.size({ includeFuture: false });
401-
events.push(`Queue size after second enqueue (including future): ${size2}`);
402-
events.push(`Queue size after second enqueue (present only): ${size2Present}`);
403395
expect(size2).toBe(1); // Should still be 1 as it's the same ID
404396

405397
// Wait for the first job to complete
406398
while (!firstJobCompleted) {
407399
await new Promise((resolve) => setTimeout(resolve, 10));
408400
}
409-
events.push("First job completed");
410401

411402
// Check queue size right after first job completes
412403
const size3 = await worker.queue.size({ includeFuture: true });
413404
const size3Present = await worker.queue.size({ includeFuture: false });
414-
events.push(`Queue size after first job completes (including future): ${size3}`);
415-
events.push(`Queue size after first job completes (present only): ${size3Present}`);
416405

417406
// Wait long enough for the second job to become available and potentially run
418407
await new Promise((resolve) => setTimeout(resolve, 2000));
419408

420409
// Final queue size
421410
const size4 = await worker.queue.size({ includeFuture: true });
422411
const size4Present = await worker.queue.size({ includeFuture: false });
423-
events.push(`Final queue size (including future): ${size4}`);
424-
events.push(`Final queue size (present only): ${size4Present}`);
425-
426-
console.log("Event sequence:", events);
427412

428413
// First job should have run
429414
expect(processedPayloads).toContain("first-attempt");

0 commit comments

Comments
 (0)