shared/common/aws-service.ts
Properties |
|
Methods |
constructor(debugLogsAllowed)
|
||||
Defined in shared/common/aws-service.ts:17
|
||||
Constructor @param debugLogAllower {boolean = false} - enable or disable additional logs
Parameters :
|
Private Readonly debugLogsAllowed |
Type : boolean
|
Default value : true
|
Defined in shared/common/aws-service.ts:15
|
flag for additional debug logs |
Private Readonly logger |
Default value : new Logger(AwsService.name)
|
Defined in shared/common/aws-service.ts:17
|
logger |
allowCronRun | ||||||||
allowCronRun(forceCronRun)
|
||||||||
Defined in shared/common/aws-service.ts:47
|
||||||||
Checks if cron run is allowed @param forceCronRun - allow some methods to still be run on non cron running environments. @return {boolean} - instance is lead
Parameters :
Returns :
boolean
|
allowLeadRoutines |
allowLeadRoutines()
|
Defined in shared/common/aws-service.ts:67
|
Checks if lead tasks are allowed @return {boolean} - instance is lead
Returns :
boolean
|
Private isCurrentServerTheLeadInstance |
isCurrentServerTheLeadInstance()
|
Defined in shared/common/aws-service.ts:33
|
Checks if current instance (pod with one instance) is lead (can do cron/gameSave tasks) @return {boolean} - is instance lead
Returns :
boolean
|
import { Logger } from '@nestjs/common';
/**
* Method to check if environment configured to run cron tasks (env.RUN_CRON !== 'no')
*
* @return {boolean}
*/
export const isCronRunningEnvironment = (): boolean => {
if (!!process.env.WEBSOCKET_NO_REDIS) return true
return process.env.RUN_CRON !== 'no';
};
export class AwsService {
/** flag for additional debug logs */
private readonly debugLogsAllowed: boolean = true;
/** logger */
private readonly logger = new Logger(AwsService.name);
/**
* Constructor
*
* @param debugLogAllower {boolean = false} - enable or disable additional logs
*/
constructor(debugLogsAllowed = false) {
this.debugLogsAllowed = debugLogsAllowed;
}
/**
* Checks if current instance (pod with one instance) is lead (can do cron/gameSave tasks)
*
* @return {boolean} - is instance lead
*/
private isCurrentServerTheLeadInstance(): boolean {
if (process.env.NODE_ENV === 'development') return true;
if (process.env.IS_LEAD_SERVER === 'yes') return true;
if (!!process.env.WEBSOCKET_NO_REDIS) return true
return false;
}
/**
* Checks if cron run is allowed
*
* @param forceCronRun - allow some methods to still be run on non cron running environments.
*
* @return {boolean} - instance is lead
*/
allowCronRun(forceCronRun = false) {
if (process.env.NODE_ENV === 'development') {
return true;
}
if (!forceCronRun && isCronRunningEnvironment() === false) {
return false;
}
// Check it everytime because the list of servers changes constantly,
// eg the previous lead instance might be killed and now this server
// is the new lead.
return this.isCurrentServerTheLeadInstance();
}
/**
* Checks if lead tasks are allowed
*
* @return {boolean} - instance is lead
*/
allowLeadRoutines(): boolean {
if (process.env.NODE_ENV === 'development') return true;
if (!!process.env.WEBSOCKET_NO_REDIS) return true
return this.isCurrentServerTheLeadInstance();
}
}