之前有分析过 bull 的 priority 和 lifo 是如何实现的
当优先级为0时,lifo 为 false 意味着使用 LPUSH,lifo 为 true 意味着使用 RPUSH
当优先级不为0时,会使用 priority zset 里的优先级排序来计算 job 应该插入哪个位置
这存在一个显而易见的问题,就是 lifo 为 true 的 job 不会放在 priority zset 里
所以 lifo 为 true 的 job 会打乱优先级的排序
-- Standard or priority add
local priority = tonumber(ARGV[9])
if priority == 0 then
-- LIFO or FIFO
rcall(ARGV[10], target, jobId) -- push to wait or paused list
else
-- Priority add
rcall("ZADD", KEYS[6], priority, jobId) -- add to priority zset
local count = rcall("ZCOUNT", KEYS[6], 0, priority)
local len = rcall("LLEN", target)
local id = rcall("LINDEX", target, len - (count-1))
if id then -- means has lower priority job
rcall("LINSERT", t
本文探讨了Bull任务队列中priority和lifo特性的实现与潜在问题。当lifo为false时,使用LPUSH;为true时,使用RPUSH。然而,lifo为true的job不会进入priority zset,导致优先级排序被打乱。通过脚本测试验证了这一现象,说明这两个特性在bull中无法同时得到有效的优先级排序保障。
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



