Something went wrong. Try again.
zig port of github.com/chrisguidry/docket
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950-- ack.lua---- terminal ack for a stream message. removes the message from the consumer-- group's pending list and the stream itself, and writes a terminal state-- to the runs hash when the hash still belongs to this message.---- The runs hash is a tombstone kept for observability, so it MUST expire.-- Every add without a key mints a fresh one (and perpetuals once minted one-- per reschedule), so without a TTL each run leaves one hash behind forever:-- a live deployment accumulated 57,300 `prefect:runs:*` keys with TTL -1 and-- OOM-killed its 256Mi Redis roughly every other day. pydocket applies the same TTL (`execution_ttl`, default-- 15 minutes) and deletes outright when it is zero.---- KEYS:-- [1] stream_key — {prefix}:stream-- [2] runs_key — {prefix}:runs:{task_key}---- ARGV:-- [1] group_name — XREADGROUP consumer-group name-- [2] msg_id — the stream message ID returned by XREADGROUP-- [3] terminal_state — 'completed' | 'failed'-- [4] execution_ttl — seconds to retain the tombstone; 0 = delete now---- returns: 'OK'
local stream_key = KEYS[1]local runs_key = KEYS[2]local group_name = ARGV[1]local msg_id = ARGV[2]local terminal_state = ARGV[3]local execution_ttl = tonumber(ARGV[4]) or 0
redis.call('XACK', stream_key, group_name, msg_id)redis.call('XDEL', stream_key, msg_id)
-- a perpetual that rescheduled itself, or a copy of one that a dead worker-- left behind, no longer owns the runs hashif redis.call('HGET', runs_key, 'stream_id') ~= msg_id then return 'OK'end
if execution_ttl > 0 then redis.call('HSET', runs_key, 'state', terminal_state) redis.call('EXPIRE', runs_key, execution_ttl)else redis.call('DEL', runs_key)end
return 'OK'