Dispatcher Class
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
Item Index
Events
Methods
applyCommandResponse
-
cmdId
-
result
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
ObjectThe id of the command associated with the response
-
result
ObjectThe actual command response
Returns:
The promise associated with the applyCommand operation and not the promise associated with the command itself.
emitTo
-
agentId
-
key
-
data
-
options
Emit an event to a specific agent only.
Parameters:
-
agentId
String | ArrayThe agent where the event is to be sent. This may be an array of agentIds.
-
key
StringThe event key that is being sent
-
data
ObjectThe event payload
-
options
Object
Returns:
A promise resolved when the event has been retrieved by the agent (or agents)
executeOnAgent
-
agentId
-
commandKey
-
payload
-
options
Execute a command on a specific agent
Parameters:
-
agentId
StringThe agentId where the command will be executed
-
commandKey
StringThe command key that identified this command
-
payload
ObjectThe data that will be passed with the command
-
options
ObjectContains options that affects the way the command is executed
Returns:
A promise providing access to the command result when available.
listen
()
Promise
Connect the HTTP server to the configured port.
Returns:
Resolved when the dispatcher is ready to receive commands.
listPendingCommands
-
agentId
List all pending commands for a specific agent
Parameters:
-
agentId
StringAn agentId
Returns:
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
ErrorThe error that has been sent.