Fix. Properly stop (e.g. remove pid file) event consumer loop in case of error. (#1766)

This commit is contained in:
Alexey Melnichuk
2016-07-21 16:47:54 +03:00
committed by FusionPBX
parent 1279c80d8a
commit 207cf08e88

View File

@@ -501,7 +501,7 @@ function EventConsumer:bind(event_name, cb)
end
end
function EventConsumer:run()
function EventConsumer:_run()
self._running = true
-- set some huge default interval
@@ -540,6 +540,18 @@ function EventConsumer:run()
self._running = false
end
function EventConsumer:run()
local ok, err = xpcall(function()
self:_run()
end, debug.traceback)
if not ok then
-- ensure we stop loop and remove pid file
self:stop()
error(err)
end
end
function EventConsumer:stop()
self._running = false
if self._pid_file and self:_check_pid_file() then