Options
All
  • Public
  • Public/Protected
  • All
Menu

The sharding manager.

example
const { isMaster } = require('cluster');
const { Fleet } = require('eris-fleet');
const path = require('path');
const { inspect } = require('util');
require('dotenv').config();

const options = {
path: path.join(__dirname, "./bot.js"),
token: process.env.token
}

const Admiral = new Fleet(options);

if (isMaster) {
// Code to only run for your master process
Admiral.on('log', m => console.log(m));
Admiral.on('debug', m => console.debug(m));
Admiral.on('warn', m => console.warn(m));
Admiral.on('error', m => console.error(inspect(m)));

// Logs stats when they arrive
Admiral.on('stats', m => console.log(m));
}
fires

Admiral#log Message to log. Supplies either a message or an ObjectLog.

fires

Admiral#debug Debug message to log. Supplies either a message or an ObjectLog.

fires

Admiral#warn Warning message to log. Supplies either a message or an ObjectLog.

fires

Admiral#error Error to log. Supplies either a message or an ObjectLog.

fires

Admiral#clusterReady Fires when a cluster is ready. Supplies Cluster Object.

fires

Admiral#serviceReady Fires when a service is ready. Supplies Service Object.

fires

Admiral#clusterShutdown Fires when a cluster is shutdown. Supplies Cluster Object.

fires

Admiral#serviceShutdown Fires when a service is shutdown. Supplies Service Object.

fires

Admiral#ready Fires when the queue is empty.

fires

Admiral#stats Fires when stats are ready. Supplies Stats

fires

Admiral#reshardingComplete Fires when resharding completes.

fires

Admiral#shardReady Fires when a shard is ready. Supplies ShardUpdate.

fires

Admiral#shardConnect Fires when a shard connects. Supplies ShardUpdate.

fires

Admiral#shardDisconnect Fires when a shard disconnects. Supplies ShardUpdate.

fires

Admiral#shardResume Fires when a shard resumes. Supplies ShardUpdate.

Hierarchy

  • EventEmitter
    • Fleet

Index

Constructors

Properties

BotWorker?: typeof BaseClusterWorker

BotWorker class used when starting clusters

broadcastAdmiralEvents: boolean
centralStore: Map<string, any>

Central storage map

chunks?: number[][]
clientOptions: ClientOptions
clusterCount: number | "auto"
clusterTimeout: number
clusters: Collection<number, ClusterCollection>

Map of clusters by ID

clustersSequentialFailedRestarts: Map<number, number>

Map of cluster ID to sequential failed restarts

collectingStats: boolean
connectedClusterGroups: Map<number, number>

Map of cluster group number to the number of times that group's members have connected

eris: Client

Eris client used to get the gateway information and to send requests when using the central request handler

erisClient: typeof Client
fetchTimeout: number
fetches: Map<string, { UUID: number | "master"; checked: number; id: string | number; op: string }>
firstShardID: number
guildsPerShard: number | "auto"
ipc: IPC

IPC for the Admiral which functions like the worker IPC classes. Has some redundant functions which already exist on the Admiral class.

killTimeout: number
lastShardID: number
launchingManager: Map<number, { waiting: any } | "launched">
launchingWorkers: Collection<number, WorkerCollection>

Maps of workers currently launching by ID

loadClusterCodeImmediately: boolean
maxConcurrency: number
maxConcurrencyOverride?: number
maxRestarts: number
nodeArgs?: string[]
objectLogging: boolean
overrideConsole: boolean
path?: string

Path used when starting clusters

pauseStats: boolean
prelimStats?: Stats
queue: Queue
resharding: boolean
serviceTimeout: number
services: Collection<string, ServiceCollection>

Map of services by name

servicesSequentialFailedRestarts: Map<string, number>

Map of service name to sequential failed restarts

servicesToCreate?: ServiceCreator[]

Services to create

shardCount: number | "auto"
shutdownTogether: boolean
softKills: Map<number, { id?: string | number; type?: "cluster" | "service"; fn: any }>
startServicesTogether: boolean
startingStatus?: StartingStatus
stats?: Stats

Current stats

statsInterval: number | "disable"
statsStarted: boolean
statsWorkersCounted?: number
token: string
useCentralRequestHandler: boolean
whatToLog: LoggingOptions[]
captureRejectionSymbol: typeof captureRejectionSymbol
captureRejections: boolean

Sets or gets the default captureRejection value for all emitters.

defaultMaxListeners: number
errorMonitor: typeof errorMonitor

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Methods

  • addListener(event: string | symbol, listener: (...args: any[]) => void): Fleet
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Fleet

  • broadcast(op: string, msg?: unknown): void
  • Broadcast an event to all clusters and services. The event can be listened to with register

    example
    admiral.broadcast("hello clusters!", "Want to chat?");
    

    Parameters

    • op: string

      Name of the event

    • Optional msg: unknown

    Returns void

  • calculateShards(): Promise<number>
  • centralApiRequest(worker: Worker, UUID: string, data: { _route?: string; auth?: boolean; body?: {}; file?: FileContent; fileString?: string; method: RequestMethod; short?: boolean; url: string }): void
  • Parameters

    • worker: Worker
    • UUID: string
    • data: { _route?: string; auth?: boolean; body?: {}; file?: FileContent; fileString?: string; method: RequestMethod; short?: boolean; url: string }
      • Optional _route?: string
      • Optional auth?: boolean
      • Optional body?: {}
        • [s: string]: unknown
      • Optional file?: FileContent
      • Optional fileString?: string
      • method: RequestMethod
      • Optional short?: boolean
      • url: string

    Returns void

  • chunk(shards: number[], clusters: number): number[][]
  • chunkConcurrencyGroups(): Map<number, number>
  • collectStats(): Promise<Stats>
  • Create a service

    example
    const path = require("path");
    admiral.createService("myService", path.join(__dirname, "./service.js"))

    Parameters

    • serviceName: string

      Unique ame of the service

    • service: string | typeof BaseServiceWorker

      Absolute path to the service file or your ServiceWorker class (extends BaseServiceWorker)

    Returns void

  • debug(message: unknown, source?: string): void
  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

  • emitLog(type: "log" | "info" | "error" | "warn" | "debug", message: unknown, source?: string): void
  • Parameters

    • type: "log" | "info" | "error" | "warn" | "debug"
    • message: unknown
    • Optional source: string

    Returns void

  • error(message: unknown, source?: string): void
  • eventNames(): (string | symbol)[]
  • Returns (string | symbol)[]

  • executeStats(): void
  • fetchInfo(op: string, id: string | number, requestWorker: FakeWorker): void
  • getMaxListeners(): number
  • Returns number

  • info(message: unknown, source?: string): void
  • ipcLog(type: "log" | "info" | "error" | "warn" | "debug", message: unknown, worker: FakeWorker): void
  • Parameters

    • type: "log" | "info" | "error" | "warn" | "debug"
    • message: unknown
    • worker: FakeWorker

    Returns void

  • ipcMessageHandler(worker: FakeWorker, message: any): void
  • ipcReturn(message: { UUID: string | number; value: { id: string | symbol; noValue?: boolean; value: any } }): void
  • Parameters

    • message: { UUID: string | number; value: { id: string | symbol; noValue?: boolean; value: any } }
      • UUID: string | number
      • value: { id: string | symbol; noValue?: boolean; value: any }
        • id: string | symbol
        • Optional noValue?: boolean
        • value: any

    Returns void

  • launch(): void
  • listenerCount(event: string | symbol): number
  • Parameters

    • event: string | symbol

    Returns number

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

  • log(message: unknown, source?: string): void
  • off(event: string | symbol, listener: (...args: any[]) => void): Fleet
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Fleet

  • on(event: string | symbol, listener: (...args: any[]) => void): Fleet
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Fleet

  • once(event: string | symbol, listener: (...args: any[]) => void): Fleet
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Fleet

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): Fleet
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Fleet

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): Fleet
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Fleet

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

  • removeAllListeners(event?: string | symbol): Fleet
  • Parameters

    • Optional event: string | symbol

    Returns Fleet

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): Fleet
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Fleet

  • restartAllClusters(hard: boolean): void
  • Restarts all clusters

    Parameters

    • hard: boolean

      Whether to ignore the soft shutdown function

    Returns void

  • restartAllServices(hard: boolean): void
  • Restarts all services

    Parameters

    • hard: boolean

      Whether to ignore the soft shutdown function

    Returns void

  • restartCluster(clusterID: number, hard: boolean): void
  • Restarts a specific cluster

    Parameters

    • clusterID: number

      ID of the cluster to restart

    • hard: boolean

      Whether to ignore the soft shutdown function

    Returns void

  • restartService(serviceName: string, hard: boolean): void
  • Restarts a specific service

    Parameters

    • serviceName: string

      Name of the service

    • hard: boolean

      Whether to ignore the soft shutdown function

    Returns void

  • restartWorker(worker: Worker, manual?: boolean, soft?: boolean): undefined | { message: { clientOptions: ClientOptions; clusterCount: number; clusterID: number; firstShardID: number; lastShardID: number; loadClusterCodeImmediately: boolean; op: string; path: undefined | string; resharding: boolean; serviceName: undefined; shardCount: number; startingStatus: undefined | StartingStatus; timeout: undefined; token: string; useCentralRequestHandler: boolean; whatToLog: LoggingOptions[] }; type: string; workerID: number } | { message: { clientOptions: undefined; clusterCount: undefined; clusterID: undefined; firstShardID: undefined; lastShardID: undefined; loadClusterCodeImmediately: undefined; op: string; path: undefined | string; resharding: undefined; serviceName: string; shardCount: undefined; startingStatus: undefined; timeout: number; token: undefined; useCentralRequestHandler: undefined; whatToLog: LoggingOptions[] }; type: string; workerID: number }
  • Parameters

    • worker: Worker
    • Optional manual: boolean
    • Optional soft: boolean

    Returns undefined | { message: { clientOptions: ClientOptions; clusterCount: number; clusterID: number; firstShardID: number; lastShardID: number; loadClusterCodeImmediately: boolean; op: string; path: undefined | string; resharding: boolean; serviceName: undefined; shardCount: number; startingStatus: undefined | StartingStatus; timeout: undefined; token: string; useCentralRequestHandler: boolean; whatToLog: LoggingOptions[] }; type: string; workerID: number } | { message: { clientOptions: undefined; clusterCount: undefined; clusterID: undefined; firstShardID: undefined; lastShardID: undefined; loadClusterCodeImmediately: undefined; op: string; path: undefined | string; resharding: undefined; serviceName: string; shardCount: undefined; startingStatus: undefined; timeout: number; token: undefined; useCentralRequestHandler: undefined; whatToLog: LoggingOptions[] }; type: string; workerID: number }

  • setMaxListeners(n: number): Fleet
  • Parameters

    • n: number

    Returns Fleet

  • shutdownCluster(clusterID: number, hard: boolean): void
  • Shuts down a cluster

    Parameters

    • clusterID: number

      The ID of the cluster to shutdown

    • hard: boolean

      Whether to ignore the soft shutdown function

    Returns void

  • shutdownService(serviceName: string, hard: boolean): void
  • Shuts down a service

    Parameters

    • serviceName: string

      The name of the service

    • hard: boolean

      Whether to ignore the soft shutdown function

    Returns void

  • startCluster(): void
  • startService(servicesToStart?: ServiceCreator[], onlyServices?: boolean): Promise<void>
  • startStats(): void
  • totalShutdown(hard: boolean): void
  • Shuts down everything and exits the master process

    Parameters

    • hard: boolean

      Whether to ignore the soft shutdown function

    Returns void

  • Updates the BotWorker used by eris-fleet. The new class will be used the next time clusters are restarted.

    Parameters

    Returns void

  • warn(message: unknown, source?: string): void
  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

  • on(emitter: EventEmitter, event: string): AsyncIterableIterator<any>
  • Parameters

    • emitter: EventEmitter
    • event: string

    Returns AsyncIterableIterator<any>

  • once(emitter: NodeEventTarget, event: string | symbol): Promise<any[]>
  • once(emitter: DOMEventTarget, event: string): Promise<any[]>
  • Parameters

    • emitter: NodeEventTarget
    • event: string | symbol

    Returns Promise<any[]>

  • Parameters

    • emitter: DOMEventTarget
    • event: string

    Returns Promise<any[]>

Generated using TypeDoc