Show:

The dispatcher is responsible for central coordination of all agents. It monitors their liveness and make sure they can communication between one and other. The Dispatcher is an {EventEmitter} and will make sure events are remotely replicated between agents.

Constructor

Dispatcher

(
  • cfg
)

Parameters:

  • cfg Object

Methods

applyCommandResponse

(
  • cmdId
  • result
)
defer.promise |

Called when an agent has sent back the response to an active command. This will apply the response and resolve the associated promise.

Parameters:

  • cmdId Object

    The id of the command associated with the response

  • result Object

    The actual command response

Returns:

defer.promise | :

The promise associated with the applyCommand operation and not the promise associated with the command itself.

emitTo

(
  • agentId
  • key
  • data
  • options
)
Promise

Emit an event to a specific agent only.

Parameters:

  • agentId String | Array

    The agent where the event is to be sent. This may be an array of agentIds.

  • key String

    The event key that is being sent

  • data Object

    The event payload

  • options Object

Returns:

Promise:

A promise resolved when the event has been retrieved by the agent (or agents)

executeOnAgent

(
  • agentId
  • commandKey
  • payload
  • options
)
Promise

Execute a command on a specific agent

Parameters:

  • agentId String

    The agentId where the command will be executed

  • commandKey String

    The command key that identified this command

  • payload Object

    The data that will be passed with the command

  • options Object

    Contains options that affects the way the command is executed

Returns:

Promise:

A promise providing access to the command result when available.

listen

() Promise

Connect the HTTP server to the configured port.

Returns:

Promise:

Resolved when the dispatcher is ready to receive commands.

listPendingCommands

(
  • agentId
)
Array

List all pending commands for a specific agent

Parameters:

  • agentId String

    An agentId

Returns:

Array:

A list of pending commands. Each command has the following fields:

  • id
  • agentId
  • defer: The deferred result
  • status: the status of the command : PENDING | ACTIVE | COMPLETE
  • ts : The unix timestamp when this command was created

Events

internal.db.error

Triggered if the internal Redis database cannot be accessed.

Event Payload:

  • e Error

    The error that has been sent.