-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
random retryDelay #94
Comments
@sylvainlap Thank you for reporting this issue. I believe that I will investigate the issue ASAP. Further updates will be posted later, so keep tuned. |
This is not a bug. After a quick checkup, I came to the conclusion that issue you reported is actually a normal behavior and it is not a bug. Let me make it more clear to you. Here the script I used for testing: import { Consumer, Producer, Message, QueueManager } from 'redis-smq';
Message.setDefaultConsumeOptions({
ttl: 0,
retryThreshold: 5,
retryDelay: 2000,
});
const queue = `queue_${Date.now()}`;
const consume = () => {
const consumer = new Consumer();
consumer.consume(
queue,
(msg) => {
console.log(`Received message ID ${msg.getId()} at ${Date.now()}`);
throw new Error('Explicit error');
},
(err) => {
if (err) console.log(err);
},
);
consumer.run();
};
const produce = () => {
const producer = new Producer();
producer.run((err) => {
if (err) console.log(err);
else {
const msg = new Message().setBody('test message').setQueue(queue);
producer.produce(msg, (err) => {
if (err) console.log(err);
else
console.log(
`Message ID ${msg.getId()} has been published at ${Date.now()}.`,
);
});
}
});
};
QueueManager.createInstance({}, (err, queueManager) => {
if (err) console.log(err);
else {
queueManager?.queue.create(queue, false, (err) => {
if (err) console.log(err);
else {
produce();
consume();
}
});
}
}); You should first understand the way RedisSMQ works. RedisSMQ uses workers for various background tasks and one of those workers is the Another crucial moment that needs to be taken into account is that the workers are allowed to run only from a single consumer instance, given many consumer instances. So for each consumer instance, before running background workers, it tries to indefinitely acquire a global lock. Once the lock is acquired, the workers are launched. An acquired lock is set to expire after 60 seconds. When you run the script above for the first time, a fresh lock is acquired and the After that if you run the script for the second time, the lock is not acquired immediately because the previous lock, which was not released, has not yet expired. Once the lock is expired, the consumer acquires a new lock and from then the message is re-queued with respect to Additionally, it is worth to mention that JavaScript clocks are not precise and are allowed to drift randomly. So when you set the |
Closing as resolved. |
Great response ! Thanks ! |
Hi.
I want to use redis-smq in my project, and wrote some tests to test the lib, but I got some random behavior with retryDelay.
In my config file, I have:
I wrote an handler that will always fail:
and register it
rsmq.consumer.consume(config.get('rsmq.queueName'), handler, () => {});
With the retryDelay, the handler should be called 3 times, at 2sec intervals. But the behavior is:
So the
retryThreshold
is respected, but not theretryDelay
. How comes ?The text was updated successfully, but these errors were encountered: