diff --git a/gateway/src/apicast/policy/3scale_batcher/3scale_batcher.lua b/gateway/src/apicast/policy/3scale_batcher/3scale_batcher.lua index 7ff5c1bdb..26a8a5d3f 100644 --- a/gateway/src/apicast/policy/3scale_batcher/3scale_batcher.lua +++ b/gateway/src/apicast/policy/3scale_batcher/3scale_batcher.lua @@ -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) @@ -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)