2023-09-07 05:44:19 -07:00
|
|
|
export type RedisServiceCommand = 'getStatus' | 'getId' | 'restartEventBus' | 'stopWorker'; // TODO: add more commands
|
2023-08-02 03:51:25 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An object to be sent via Redis pub/sub from the main process to the workers.
|
|
|
|
* @field command: The command to be executed.
|
|
|
|
* @field targets: The targets to execute the command on. Leave empty to execute on all workers or specify worker ids.
|
2023-09-07 05:44:19 -07:00
|
|
|
* @field payload: Optional arguments to be sent with the command.
|
2023-08-02 03:51:25 -07:00
|
|
|
*/
|
|
|
|
type RedisServiceBaseCommand = {
|
2023-09-07 05:44:19 -07:00
|
|
|
senderId: string;
|
2023-08-02 03:51:25 -07:00
|
|
|
command: RedisServiceCommand;
|
|
|
|
payload?: {
|
|
|
|
[key: string]: string | number | boolean | string[] | number[] | boolean[];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export type RedisServiceWorkerResponseObject = {
|
|
|
|
workerId: string;
|
2023-09-07 05:44:19 -07:00
|
|
|
} & (
|
|
|
|
| RedisServiceBaseCommand
|
|
|
|
| {
|
|
|
|
command: 'getStatus';
|
|
|
|
payload: {
|
|
|
|
workerId: string;
|
|
|
|
runningJobs: string[];
|
|
|
|
freeMem: number;
|
|
|
|
totalMem: number;
|
|
|
|
uptime: number;
|
|
|
|
loadAvg: number[];
|
|
|
|
cpus: string[];
|
|
|
|
arch: string;
|
|
|
|
platform: NodeJS.Platform;
|
|
|
|
hostname: string;
|
|
|
|
net: string[];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
command: 'getId';
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
command: 'restartEventBus';
|
|
|
|
payload: {
|
|
|
|
result: 'success' | 'error';
|
|
|
|
error?: string;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
command: 'stopWorker';
|
|
|
|
}
|
|
|
|
);
|
2023-08-02 03:51:25 -07:00
|
|
|
|
|
|
|
export type RedisServiceCommandObject = {
|
|
|
|
targets?: string[];
|
|
|
|
} & RedisServiceBaseCommand;
|