event

Summit Service and Event Library.

Functions

Name Summary
bind

Bind events to callbacks. (Summit Service Only)

calls

Get list of info about live calls running under this service (Summit Service Only)

interval

Schedule periodic tasks. (Summit Service Only)

register_init

Register an initialization function (Summit Service Only)

send

Send custom events.

set_watchdog_timeout

Set Watchdog Timeout.

Functions : event

bind(event_type, callback)

Bind events to callbacks. (Summit Service Only)

Parameters
Name Type Default Summary

event_type

string

Name of an expected event.

callback

function

A function to be called when the even occurs.

Returns
Type Summary

nil

Usage
local event = require "summit.event"
    local http = require "summit.http"

    function handle_new_call(event)
      http.post("http://example.com/got_a_new_call", {data=tostring(event)})
    end

    event.bind("newcall", handle_new_call)

calls()

Get list of info about live calls running under this service (Summit Service Only)

Returns
Type Summary

table or nil

array of tables containing call_id and channel_id for each live call running under the current service, or nil on error.

nil or string

nil if successful, error message otherwise

Usage
local event = require "summit.event"
    local log = require "summit.log"

    local calls, err = event.calls()

    if calls then
      log.info(("There are currently %s active calls"):format(#calls))

      local channel_ids = {}
      for _, call in ipairs(calls) do
        table.insert(channel_ids, call.channel_id)
      end
      log.info(("One of the channel_id's is: %s"):format(channel_ids[1]))
    else
      log.error(err)
    end

interval(interval, callback)

Schedule periodic tasks. (Summit Service Only)

Parameters
Name Type Default Summary

interval

int

Name of an expected event.

callback

function

A function to be called periodically.

Returns
Type Summary

nil

Usage
local event = require "summit.event"
  local time = require "summit.time"
  local http = require "summit.http"

  function report_uptime(event)
    local start_time = time.now("US/Central")
    local start_ts = time.to_unix_timestamp(start_time)
    return function ()
      local t = time.now("US/Central")
      local ts = time.to_unix_timestamp(t)
      message = "uptime: "..tostring(ts - start_ts).." seconds"
      http.post("http://example.com/uptime_report", {data=message})
    end
  end

  event.interval(10, report_uptime())

register_init(callback)

Register an initialization function (Summit Service Only) When a Summit Service starts, the registered initialization function will be called with no arguments after the entire service.lua file has been read and after the event listener has been started. Calls can proceed before this function has completed, however no event callbacks will be processed until this function has completed. Events sent from inside the registered init function will cause callbacks to fire. Events sent from anywhere else in summit.lua will not do so.

Only one function can be registered, registering more than once will result in the previously registered function to be forgotten. If an exception is raised during execution of this function, it will be treated like any other callback — it will be logged, but the service will still run.

Parameters
Name Type Default Summary

callback

function

The initialization function for a Summit Service.

Returns
Type Summary

nil

Usage
local event = require "summit.event"
    local time = require "summit.time"

    local service_state = {}

    function initialize()  -- init function takes no arguments
      service_state.start_time = time.now("America/Chicago")
      event.send("initialized")  -- you can send events in here
    end

    event.register_init(initialize)

send(event_type, message)

Send custom events.

Parameters
Name Type Default Summary

event_type

string

Name of an custom event.

message

string

A function to be called when the even occurs.

Returns
Type Summary

nil

Usage
local event = require "summit.event"

    event.send("callstatus", "hanging_up")
    channel.hangup()

set_watchdog_timeout(timeout)

Set Watchdog Timeout. Setting a watchdog timer will cause the Summit Service to monitor the responsiveness of the callback processor system. If for any reason the callback processor shows no activity — most likely a non-returning callback — for more than the prescribed number of seconds, the Summit Service will be shut down. A graceful shutdown is attempted first, and a hard termination will be done if that fails. In the event of a hard termination, cleanup functions might not be called.

The default is no watchdog timeout. Setting the timeout to zero will disable the watchdog timer.

Parameters
Name Type Default Summary

timeout

number

the timeout

Returns
Type Summary

number or nil

the timeout if successful, nil otherwise

nil or string

nil if successful, error message otherwise