Skip to content

Commit

Permalink
policy/3scale_batcher: define __gc to avoid leaving pending reports
Browse files Browse the repository at this point in the history
  • Loading branch information
davidor committed Jul 2, 2018
1 parent c238af4 commit 4e90e08
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion gateway/src/apicast/policy/3scale_batcher/3scale_batcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ local ipairs = ipairs
local default_auths_ttl = 10
local default_batch_reports_seconds = 10

local _M = policy.new('Caching policy')
local _M, mt = policy.new('Caching policy')

local new = _M.new

mt.__gc = function(self)
-- Instances of this policy are garbage-collected when the config is
-- reloaded. We need to ensure that the TimerTask instance schedules another
-- run before that so we do not leave any pending reports.

if self.timer_task then
self.timer_task:schedule_one(1)
end
end

function _M.new(config)
local self = new(config)

Expand Down Expand Up @@ -170,9 +180,11 @@ end
-- calls to backend.
function _M:access(context)
local backend = backend_client:new(context.service, http_ng_resty)
self.backend = backend
local usage = context.usage
local service = context.service
local service_id = service.id
self.service_id = service_id
local credentials = context.credentials
local transaction = Transaction.new(service_id, credentials, usage)

Expand Down

0 comments on commit 4e90e08

Please sign in to comment.