Skip to main content

Class: BackgroundServiceManager

Defined in: service-core/src/BackgroundServiceManager.ts:37

The BackgroundServiceManager manages all configured background services in the application. It is responsible for initializing the jobs, scheduling them and performing any related shutdown tasks. See the BackgroundService class for details on how to create a background service class to be used by this manager.

Usage

To use the manager instantiate a new object and provide the required constructor arguments. Then simply call the startAll function. When shutting your application down you should call the stopAll function.

import { BackgroundServiceManager } from "@rapidrest/service-core";

const manager: BackgroundServiceManager = new BackgroundServiceManager(objectFactory, serviceClasses, config, logger);
await manager.startAll();
...
await manager.stopAll();

You may optionally start and stop individual services using the start and stop functions respectively.

await manager.start("MyService");
...
await manger.stop("MyService");

Constructors

Constructor

new BackgroundServiceManager(objectFactory, classes): BackgroundServiceManager

Defined in: service-core/src/BackgroundServiceManager.ts:47

Parameters

objectFactory

ObjectFactory

classes

Returns

BackgroundServiceManager

Methods

getService()

getService(name): BackgroundService | undefined

Defined in: service-core/src/BackgroundServiceManager.ts:57

Returns the service instance with the given name.

Parameters

name

string

The name of the background service to retrieve.

Returns

BackgroundService | undefined


start()

start(serviceName, clazz?, ...args): Promise<void>

Defined in: service-core/src/BackgroundServiceManager.ts:83

Starts the background service with the given name.

Parameters

serviceName

string

The name of the background service to start.

clazz?

any

The class type of the service to start. If not specified the name is used to lookup the class type.

args

...any

The list of arguments to pass into the service constructor

Returns

Promise<void>


startAll()

startAll(): Promise<void>

Defined in: service-core/src/BackgroundServiceManager.ts:64

Starts all configured background services.

Returns

Promise<void>


stop()

stop(serviceName): Promise<void>

Defined in: service-core/src/BackgroundServiceManager.ts:141

Stops the background service with the given name.

Parameters

serviceName

string

The name of the background service to stop.

Returns

Promise<void>


stopAll()

stopAll(): Promise<void>

Defined in: service-core/src/BackgroundServiceManager.ts:126

Stops all currently active background services that are owned by the manager.

Returns

Promise<void>