fix(kv): claim parked jobs by member instead of secondary key (#2232)

This commit is contained in:
Hampus
2026-08-31 13:16:52 +02:00
committed by GitHub
parent 5c2dca1c51
commit eeea391b63
6 changed files with 91 additions and 12 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ export interface IKVProvider {
refillIntervalMs: number,
): Promise<number>;
scheduleBulkDeletion(queueKey: string, secondaryKey: string, score: number, value: string): Promise<void>;
removeBulkDeletion(queueKey: string, secondaryKey: string): Promise<boolean>;
removeBulkDeletion(queueKey: string, secondaryKey: string, member?: string): Promise<boolean>;
scan(pattern: string, count: number): Promise<Array<string>>;
dequeuePurgeBatch(
queueKey: string,
+7 -1
View File
@@ -224,6 +224,11 @@ redis.call('SET', bucketKey, cjson.encode({tokens = tokens, lastRefill = lastRef
return cjson.encode({urls = urls, tokens = #urls})
`;
const REMOVE_BULK_DELETION_SCRIPT = `
local member = ARGV[1]
if member ~= '' and redis.call('ZREM', KEYS[1], member) == 1 then
redis.call('DEL', KEYS[2])
return 1
end
local value = redis.call('GET', KEYS[2])
if not value then
return 0
@@ -608,13 +613,14 @@ export class KVClient implements IKVProvider {
);
}
async removeBulkDeletion(queueKey: string, secondaryKey: string): Promise<boolean> {
async removeBulkDeletion(queueKey: string, secondaryKey: string, member = ''): Promise<boolean> {
const result = await this.executeScript(
'removeBulkDeletion',
REMOVE_BULK_DELETION_SCRIPT,
2,
queueKey,
secondaryKey,
member,
);
return Number(result) === 1;
}