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 d7caa05 commit 184616c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 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:cancel(true)
end
end

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

Expand Down

0 comments on commit 184616c

Please sign in to comment.