Skip to content

Commit bc2a999

Browse files
committed
Consider the time the renewal job took when rescheduling it
With throttling, renewal jobs can take a significant time to complete (e.g. when a bunch of domains are renewing around the same time). To make sure we can spread out the renewal as evenly as possible throughout the period, and to ensure the renewal checks on different workers stay in sync, consider the duration of the actual job execution when re-scheduling the check.
1 parent e9ab9d3 commit bc2a999

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/resty/auto-ssl/jobs/renewal.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,14 @@ end
254254
local function renew(premature, auto_ssl_instance)
255255
if premature then return end
256256

257+
local start = ngx.now()
257258
local renew_ok, renew_err = pcall(do_renew, auto_ssl_instance)
258259
if not renew_ok then
259260
ngx.log(ngx.ERR, "auto-ssl: failed to run do_renew cycle: ", renew_err)
260261
end
261262

262-
local timer_ok, timer_err = ngx.timer.at(auto_ssl_instance:get("renew_check_interval"), renew, auto_ssl_instance)
263+
local delay = math.max(0, auto_ssl_instance:get("renew_check_interval") - (ngx.now() - start))
264+
local timer_ok, timer_err = ngx.timer.at(delay, renew, auto_ssl_instance)
263265
if not timer_ok then
264266
if timer_err ~= "process exiting" then
265267
ngx.log(ngx.ERR, "auto-ssl: failed to create timer: ", timer_err)

0 commit comments

Comments
 (0)