fix: harden multi-instance scheduler and worker execution
This commit is contained in:
1 parent
df7dcd3a9c
commit
60a006008a
23 files changed
+1442
-299
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { RedisService } from './redis.service';
|
||||
|
||||
function createRedisService(client: Record<string, unknown>) {
|
||||
return new RedisService(client as never);
|
||||
}
|
||||
|
||||
describe('RedisService stream pending recovery', () => {
|
||||
it('normalizes XAUTOCLAIM array replies into stream entries', async () => {
|
||||
const sendCommand = jest.fn().mockResolvedValue([
|
||||
'0-0',
|
||||
[
|
||||
[
|
||||
'1700000000000-0',
|
||||
['job', '{"kind":"poll-tournament-result"}', 'source', 'test'],
|
||||
],
|
||||
],
|
||||
]);
|
||||
const service = createRedisService({ sendCommand });
|
||||
|
||||
await expect(
|
||||
service.claimStalePendingStreamMessages({
|
||||
key: 'riot:queue:high',
|
||||
group: 'riot-refresh-worker',
|
||||
consumer: 'worker-1',
|
||||
stalePendingMessageMinimumIdleMilliseconds: 1_800_000,
|
||||
count: 1,
|
||||
}),
|
||||
).resolves.toEqual({
|
||||
nextStartId: '0-0',
|
||||
messages: [
|
||||
{
|
||||
id: '1700000000000-0',
|
||||
message: {
|
||||
job: '{"kind":"poll-tournament-result"}',
|
||||
source: 'test',
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(sendCommand).toHaveBeenCalledWith([
|
||||
'XAUTOCLAIM',
|
||||
'riot:queue:high',
|
||||
'riot-refresh-worker',
|
||||
'worker-1',
|
||||
'1800000',
|
||||
'0-0',
|
||||
'COUNT',
|
||||
'1',
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user