Skip to content

[Code Quality] Hardcoded Loop in Polling Architecture #8

@Hellnight2005

Description

@Hellnight2005

Location:
api-gateway


Description:
Manual while(true) polling is used instead of a dedicated queue worker.
A proper queue library (e.g., bullmq, already in dependencies) handles concurrency, backoff, and error handling much more robustly.


Problem:

  • Manual loops can cause CPU spikes if not handled correctly
  • Error handling and retries are harder to manage
  • Concurrency control is missing

Proposed Solution:

  • Refactor consumer.ts to use a robust worker pattern
  • Alternatively, ensure the manual loop has proper flow control, backoff, and error handling
// Example: Using a BullMQ worker instead of manual while(true)
import { Worker } from 'bullmq';

const myWorker = new Worker('queueName', async job => {
  // handle job
}, {
  connection: redisConnection
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions