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:
-
cfgObject
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:
-
cmdIdObjectThe id of the command associated with the response
-
resultObjectThe 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:
-
agentIdString | ArrayThe agent where the event is to be sent. This may be an array of agentIds.
-
keyStringThe event key that is being sent
-
dataObjectThe event payload
-
optionsObject
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:
-
agentIdStringThe agentId where the command will be executed
-
commandKeyStringThe command key that identified this command
-
payloadObjectThe data that will be passed with the command
-
optionsObjectContains 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:
-
agentIdStringAn 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:
-
eErrorThe error that has been sent.
Safelink