Skip to content

Commit

Permalink
Update to more readable fix based on PR review feedback
Browse files Browse the repository at this point in the history
Simplifies the conditional to reload configuration based on the interval set by
`APICAST_CONFIGURATION_CACHE`.

Also conditionally sets the interval to schedule.
  • Loading branch information
coderbydesign authored and tkan145 committed Jul 17, 2024
1 parent fb146eb commit 491f13d
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions gateway/src/apicast/configuration_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,15 @@ function boot.init_worker(configuration)
schedule(interval, handler, ...)
end

-- Check whether the reserved boot configuration is fresh or stale.
-- If it is stale, refresh configuration
-- When a worker process is (re-)spawned,
-- it will start working with fresh (according the ttl semantics) configuration
local boot_reserved_hosts = configuration:find_by_host(boot_reserved_domain, false)
if(#boot_reserved_hosts == 0 and interval > 0)
then
-- the boot configuration has expired, load fresh config
ngx.log(ngx.INFO, 'boot time configuration has expired')
-- ngx.socket.tcp is not available at the init or init_worker phases,
-- it needs to be scheduled (with delay = 0)
schedule(0, handler, configuration)
elseif(interval > 0)
then
if interval > 0 then
-- Check whether the reserved boot configuration is fresh or stale.
-- If it is stale, refresh configuration
-- When a worker process is (re-)spawned,
-- it will start working with fresh (according the ttl semantics) configuration
local boot_reserved_hosts = configuration:find_by_host(boot_reserved_domain, false)
ngx.log(ngx.DEBUG, 'schedule new configuration loading')
schedule(interval, handler, configuration)
local curr_interval = #boot_reserved_hosts == 0 and 0 or interval
schedule(curr_interval, handler, configuration)
else
ngx.log(ngx.DEBUG, 'no scheduling for configuration loading')
end
Expand Down

0 comments on commit 491f13d

Please sign in to comment.