Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BaseServiceWorker

The base class for a service

example
const { BaseServiceWorker } = require('eris-fleet');

module.exports = class ServiceWorker extends BaseServiceWorker {
constructor(setup) {
// Do not delete this super.
super(setup);

// Run this function when your service is ready for use. This MUST be run for the worker spawning to continue.
this.serviceReady();

// Demonstration of the properties the service has (Keep reading for info on IPC):
// ID of the worker
console.log(this.workerID);
// The name of the service
console.log(this.serviceName);
}
// This is the function which will handle commands. In this example the data is {"smileyFace": ":)"}
async handleCommand(dataSentInCommand) {
// Return a response if you want to respond
return dataSentInCommand.smileyFace;
}
shutdown(done) {
// Optional function to gracefully shutdown things if you need to.
done(); // Use this function when you are done gracefully shutting down.
}
}

Hierarchy

  • BaseServiceWorker

Index

Constructors

Properties

handleCommand: (data: any) => any

Type declaration

    • (data: any): any
    • Function to handle commands. Have a function called handleCommand to your service class to handle commands.

      see

      BaseServiceWorker See for an example

      Parameters

      • data: any

        Data sent in the command

      Returns any

ipc: IPC
serviceName: string

Unique name given to the service

serviceReady: () => void

Type declaration

    • (): void
    • Function to report a service being ready

      Returns void

serviceStartingError: (error: unknown) => void

Type declaration

    • (error: unknown): void
    • Function to report error during service launch

      Parameters

      • error: unknown

        Error to report

      Returns void

shutdown?: (done: () => void) => void

Type declaration

    • (done: () => void): void
    • Graceful shutdown of the service. Have a function within your bot class called shutdown to use this.

      To handle errors, return something similar to the following: {err: "error here"}

      see

      BaseServiceWorker See for an example

      Parameters

      • done: () => void

        Call this function when your shutdown function is complete.

          • (): void
          • Returns void

      Returns void

workerID: number

ID of the worker

Generated using TypeDoc