Class: ShardingSlave

ShardingSlave


new ShardingSlave()

Starts the slave, and attempts to connect to the master immediately. Throws errors if setup is incorrect.
Source:

Members


<private, constant> _config :object

Parsed config file from disk.
Type:
  • object
Source:

<private> _evals :Map.<string, Promise>

Ongoing promises for calls to Discord's Shard#eval, mapped by the script they were called with.
Type:
  • Map.<string, Promise>
Source:

<private, nullable> _hbTimeout :number

Timeout to attempt reconnection if no heartbeat request was received from the master (pull), or the timeout until the next heartbeat will be sent (push).
Type:
  • number
Source:

<private> _lastSeen :number

The timestamp at which the last message from the master was received.
Type:
  • number
Source:

<private, constant> _privKey :string

The private key identifying this shard.
Type:
  • string
Source:

<private, nullable> _respawnTimeout :number

Timeout for respawn request.
Type:
  • number
Source:

<private, nullable> _settings :object

The settings the master has told us to operate with. This includes the botName, heartbeat settings, as well as shard ID and count. Null until a connection is established.
Type:
  • object
Source:

<private, constant> _socket :socketIo.Socket

The socket.io socket used to communicate with the master.
Type:
  • socketIo.Socket
Source:

<private> _status :ShardingMaster.ShardStatus

The current status information about this shard. This is sent to the master as a heartbeat.
Type:
Source:

<private> _verified :boolean

Has the connection to the master been verified. If false, the current connection has not been established to be the correct endpoint. This may not necessarily be a security vulnerability however, as this is a redundant check in addition to the HTTPS websocket connection.
Type:
  • boolean
Source:

<constant> id :string

This slave's ID/Name.
Type:
  • string
Source:

<constant> pubKey :string

The public key of this shard.
Type:
  • string
Source:

Methods


<private> _childMessage(message)

Handle a message from the child.
Parameters:
Name Type Description
message object A parsed JSON object or primitive value.
Source:

<private> _evalRequest(script, cb)

Master has requested shard evaluates a script.
Parameters:
Name Type Description
script string Script to evaluate on the shard.
cb function Callback function with optional error, otherwise success message is second parameter.
Source:

<private> _fetchDiskStats(cb)

Fetch disk storage information about the bot. If a value was unable to be fetched, it will return a `null` value instead of a string.
Parameters:
Name Type Description
cb function Callback with first argument as optional error, otherwise the second is an object containing stats about different directories.
Source:

<private> _generateAuthHeader()

Generate the string to pass as the `authorization` header during the connection request to the master.
Source:
Returns:
The string to pass directly to the auth header.
Type
string

<private> _generateHeartbeat()

Fetch stats necessary for heartbeat message to the master, then sends the message.
Source:

<private> _handleError(err)

Handle an error during spawning of child.
Parameters:
Name Type Description
err Error Error emitted by EventEmitter.
Source:

<private> _handleExit(code, signal)

Handle the child processes exiting.
Parameters:
Name Type Description
code number Process exit code.
signal string Process kill signal.
Source:

<private> _hbEvalResHandler(err, res)

Handler for response to status fetching for a heartbeat request.
Parameters:
Name Type Description
err Error | string Optional error message.
res * Response from eval.
Source:

<private> _hbTimeoutHandler()

Handler for _hbTimeout.
Source:

<private> _masterVerification(sig, data)

Verify that we are connecting to the master we expect.
Parameters:
Name Type Description
sig string The signature.
data string The message sent that was signed.
Source:

<private> _receiveMasterFile(filename, data, cb)

We received a file from the sharding master that it intends for us to write to disk at the given filename relative to the project root.
Parameters:
Name Type Description
filename string Filename relative to project directory.
data string | Buffer The data to write to the file, or null to delete the file.
cb function Callback once completed with optional error.
Source:

<private> _respawnChild( [delay])

Trigger the child process to be killed and restarted.
Parameters:
Name Type Argument Description
delay number <optional>
Time to wait before actually respawning in milliseconds.
Source:

<private> _sendMasterFile(filename, cb)

Send the specified file to the ShardingMaster.
Parameters:
Name Type Description
filename string Filename relative to project directory.
cb function Callback with optional error argument.
Source:

<private> _socketConnected()

Socket connected event handler.
Source:

<private> _socketConnectError( [args])

Socket connected fail event handler.
Parameters:
Name Type Argument Description
args * <optional>
<repeatable>
Error arguments.
Source:

<private> _socketDisconnected(reason)

Socket disconnected event handler.
Parameters:
Name Type Description
reason string Either ‘io server disconnect’, ‘io client disconnect’, or ‘ping timeout’.
Source:

<private> _socketReconnecting(attempt)

Socket connected event handler.
Parameters:
Name Type Description
attempt number The reconnection attempt number.
Source:

<private> _spawnChild()

Spawn the child process with the current settings available.
Source:

<private> _updateRequest(settings)

Master has sent a status update, and potentially expects a response.
Parameters:
Name Type Description
settings string Current settings for operation as JSON parsable string.
Source:

broadcastEval(script, cb)

Fire a broadcast to all shards requesting eval of given script.
Parameters:
Name Type Description
script string The script to evaluate.
cb function Callback once all shards have completed or there was an error. First argument is optional error, second will otherwise be array of responses indexed by shard IDs.
Source:
See:
  • ShardingMaster~broadcastEvalToShards

exit()

Cleanup and fully shutdown gracefully.
Source:

respawnAll( [cb])

Kills all running shards and respawns them.
Parameters:
Name Type Argument Description
cb function <optional>
Callback once all shards have been rebooted or an error has occurred.
Source:
See:
  • ShardingMaster.respawnAll

sendSQL(query, cb)

Send an SQL query to the master to run on our database.
Parameters:
Name Type Description
query string The query to evaluate.
cb function First argument is optional error, second will otherwise be response from query.
Source:
See:
  • ShardingMaster~sendSQL