lib/src/lifecycle/Unit.ts

37 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-06-03 03:36:25 +00:00
import {AppClass} from './AppClass'
2021-03-03 00:57:41 +00:00
2021-03-25 13:50:13 +00:00
/**
* The various statuses of a Unit.
*/
2021-03-03 00:57:41 +00:00
export enum UnitStatus {
Starting,
Started,
Stopping,
Stopped,
Error,
}
2021-03-25 13:50:13 +00:00
/**
* Base class for a service that can be registered with the application
* that is started and stopped during the application lifecycle.
*/
2021-03-03 00:57:41 +00:00
export abstract class Unit extends AppClass {
2021-03-25 13:50:13 +00:00
/** The current status of the unit. */
2021-03-03 00:57:41 +00:00
public status: UnitStatus = UnitStatus.Stopped
2021-03-25 13:50:13 +00:00
/**
* This method is called to start the unit when the application is booting.
* Here, you should do any setup required to get the package up and running.
*/
2021-06-03 03:36:25 +00:00
public up(): Promise<void> | void {} // eslint-disable-line @typescript-eslint/no-empty-function
2021-03-25 13:50:13 +00:00
/**
* This method is called to stop the unit when the application is shutting down.
* Here, you should do any teardown required to stop the package cleanly.
*
* IN PARTICULAR take care to free blocking resources that could prevent the
* process from exiting without a kill.
*/
2021-06-03 03:36:25 +00:00
public down(): Promise<void> | void {} // eslint-disable-line @typescript-eslint/no-empty-function
2021-03-03 00:57:41 +00:00
}