Practical Scripting Patterns
Retry Budgets
Model a bounded retry loop.
Retry Budgets
retry_budget.lua
local failures =
local max_attempts = 3
local attempt = 0
local status = "retry"
while attempt < max_attempts and status == "retry" do
attempt = attempt + 1
if attempt > failures then
status = "ok"
end
end
if status ~= "ok" then
status = "failed"
end
print("failures=" .. failures)
print("attempts=" .. attempt)
print("status=" .. status)
local failures =
local max_attempts = 3
local attempt = 0
local status = "retry"
while attempt < max_attempts and status == "retry" do
attempt = attempt + 1
if attempt > failures then
status = "ok"
end
end
if status ~= "ok" then
status = "failed"
end
print("failures=" .. failures)
print("attempts=" .. attempt)
print("status=" .. status)
local failures =
local max_attempts = 3
local attempt = 0
local status = "retry"
while attempt < max_attempts and status == "retry" do
attempt = attempt + 1
if attempt > failures then
status = "ok"
end
end
if status ~= "ok" then
status = "failed"
end
print("failures=" .. failures)
print("attempts=" .. attempt)
print("status=" .. status)
retry-budget
Retry loops need a limit. A small counter and status label show whether the script stopped because work succeeded or because the budget ran out.