ЛР6: наблюдаемость, SLO и диагностика отказов
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import json
|
||||
|
||||
PUBLISH = """
|
||||
local previous = redis.call('HGET', KEYS[2], ARGV[1])
|
||||
if previous then
|
||||
local attempt, id = string.match(previous, '^(%d+)|(%d+%-%d+)$')
|
||||
if attempt == ARGV[2] and #redis.call('XRANGE', KEYS[1], id, id, 'COUNT', 1) > 0 then
|
||||
return {id, 0}
|
||||
end
|
||||
end
|
||||
local id = redis.call('XADD', KEYS[1], '*', 'job', ARGV[3])
|
||||
redis.call('HSET', KEYS[2], ARGV[1], ARGV[2] .. '|' .. id)
|
||||
return {id, 1}
|
||||
"""
|
||||
|
||||
ACK = """
|
||||
redis.call('XACK', KEYS[1], ARGV[1], ARGV[2])
|
||||
redis.call('XDEL', KEYS[1], ARGV[2])
|
||||
local previous = redis.call('HGET', KEYS[2], ARGV[3])
|
||||
if previous then
|
||||
local attempt, id = string.match(previous, '^(%d+)|(%d+%-%d+)$')
|
||||
if id == ARGV[2] then redis.call('HDEL', KEYS[2], ARGV[3]) end
|
||||
end
|
||||
return 1
|
||||
"""
|
||||
|
||||
|
||||
def publish(broker, settings, payload):
|
||||
result = broker.eval(
|
||||
PUBLISH,
|
||||
2,
|
||||
settings.stream,
|
||||
"job-publications",
|
||||
payload["job_id"],
|
||||
payload["attempt"],
|
||||
json.dumps(payload),
|
||||
)
|
||||
return bool(result[1])
|
||||
|
||||
|
||||
def acknowledge(broker, settings, message_id, job_id=""):
|
||||
broker.eval(ACK, 2, settings.stream, "job-publications", settings.group, message_id, job_id)
|
||||
Reference in New Issue
Block a user