I'm writing a service on NodeJS that processes CPU-bound tasks. The main idea is pretty simple:
- Client (browser) sends request
- Webserver (NodeJS + ExpressJS) handles request: generates ID, adds a task to RabbitMQ with that ID and replies to client with that ID.
- Also webserver adds the task to Redis server with ID as a key and
{status: active}
as a value - Consumer processes a task in about a minute and updates redis entry with the derived result.
- Client uses this ID to check the status of the corresponding task.
The question: I wish consumer to stop processing the task in the step 4 if client has stopped asking server that the task is still running. How can I do that with RabbitMQ?
P.S.: I've tried to purge the queue but faced with some problems: the queue is not purged if the message was not acknowledged by consumer. As sad here, this will happen only after my CPU-bound task is finished.