You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

66 lines
1.1 KiB

import { Microservice } from "./Microservice";
import EventEmitter from "events";
/**
* A generic service
*/
export abstract class InternalService<T extends Microservice = Microservice> extends EventEmitter
{
/**
* The application instance
*/
protected readonly app: T;
/**
* Enable/disable logging for this service
*/
public logging: boolean = true;
/**
* Create a new service
*/
public constructor(app: T) {
super();
this.app = app;
}
// Required Service Implementation -------------------------------------------------------------
/**
* The service name
*/
public abstract readonly NAME: string;
/**
* Boot the service
*/
public async boot(): Promise<void> {
// no-op
}
/**
* Shut the application down
*/
public async shutdown(): Promise<void> {
// no-op
}
// Miscellaneous ------------------------------------------------------------------------------
/**
* Indicate the application is ready
*/
public start() {
// no-op
};
/**
* Service-specific logging
*/
public log(...args: any[]) {
if (!this.logging) {
return;
}
console.log(`[${this.NAME}]:`, ...args);
}
}