Skip to content

Commit

Permalink
Check that redis do not return empty table
Browse files Browse the repository at this point in the history
Co-authored-by: danilapog <[email protected]>
Co-committed-by: danilapog <[email protected]>
  • Loading branch information
danilapog authored and VyacheslavSemin committed Oct 10, 2024
1 parent 93b2643 commit bc77cf4
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions templates/ingresses/documentserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ metadata:
end
end
local function get_redis_data(ver)
local data
local checker
repeat
if ver then
data = red:scan(0, "count", 10000, "match", string.format('*-%s', ver))
else
data = red:scan(0, "count", 10000)
end
local nested_table = data[2]
checker = (tostring(cjson.encode(nested_table)))
if checker == "{}" then
print("WARN: Redis return empty table for some reason...")
ngx.sleep(1)
end
until checker ~= "{}"
return data
end
-- return random endpoint from redis by requested version
local function get_random_endpoint(ver, api_key)
red:select({{ .Values.documentserver.dsVersionHashRedisDBNum }})
Expand All @@ -178,11 +197,7 @@ metadata:
local endpoint_exist = false
if api_key or api_js_exist() then
repeat
if ver then
data = red:scan(0, "count", 10000, "match", string.format('*-%s', ver))
else
data = red:scan(0, "count", 10000)
end
data = get_redis_data(ver)
local static_endpoints = data[2]
local new_endpoint = tostring((static_endpoints[math.random(1, #static_endpoints)]))
random_endpoint = new_endpoint:gsub("%-.+$", "")
Expand All @@ -193,11 +208,7 @@ metadata:
end
until endpoint_exist
else
if ver then
data = red:scan(0, "count", 10000, "match", string.format('*-%s', ver))
else
data = red:scan(0, "count", 10000)
end
data = get_redis_data(ver)
local static_endpoints = data[2]
local new_endpoint = tostring((static_endpoints[math.random(1, #static_endpoints)]))
random_endpoint = new_endpoint:gsub("%-.+$", "")
Expand Down

0 comments on commit bc77cf4

Please sign in to comment.