Skip to content

Instantly share code, notes, and snippets.

@moteus
Last active December 14, 2016 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moteus/f18b8a75bdc705e3901f83a168b8798b to your computer and use it in GitHub Desktop.
Save moteus/f18b8a75bdc705e3901f83a168b8798b to your computer and use it in GitHub Desktop.
FusionPBX fax_queue_monitor based on EventCounsumer class
require "resources.functions.config"
require "resources.functions.split"
local log = require "resources.functions.log".fax_queue_monitor
local Next = require "app.fax.resources.scripts.queue.next"
local EventConsumer = require "resources.functions.event_consumer"
local pid_file = scripts_dir .. "/run/fax_queue.tmp"
local events = EventConsumer.new(pid_file)
-- FS shutdown
events:bind("SHUTDOWN", function(self, name, event)
log.notice("shutdown")
return self:stop()
end)
-- shutdown command
events:bind("CUSTOM::fusion::fax::shutdown", function(self, name, event)
log.notice("shutdown")
return self:stop()
end)
-- timeout
events:onInterval(60000, function(self)
local ok, err = pcall(function()
Next.poll_once()
end)
if not ok then
log.errf("fail poll queue: %s", tostring(err))
end
end)
log.notice("start")
events:run()
log.notice("stop")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment