2022-02-24 19:16:21 +00:00
|
|
|
import * as plugins from './bobcat.plugins';
|
2022-02-27 18:10:44 +00:00
|
|
|
import { Bobcat } from './bobcat.classes.bobcat';
|
2022-02-24 19:16:21 +00:00
|
|
|
|
|
|
|
/**
|
2022-02-27 18:10:44 +00:00
|
|
|
* a manager for managing multiple bobcats
|
2022-02-24 19:16:21 +00:00
|
|
|
*/
|
|
|
|
export class BobcatManager {
|
2022-02-27 18:10:44 +00:00
|
|
|
public taskmanager = new plugins.taskbuffer.TaskManager();
|
2022-02-25 19:36:44 +00:00
|
|
|
public bobcats: Bobcat[] = [];
|
|
|
|
|
2022-02-27 18:10:44 +00:00
|
|
|
/**
|
|
|
|
* a store for knowing what has happened retrospectively
|
|
|
|
*/
|
|
|
|
public actionStore: {
|
|
|
|
actionName: string;
|
|
|
|
actionPayload: string;
|
|
|
|
}[] = [];
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.taskmanager.addAndScheduleTask(new plugins.taskbuffer.Task({
|
|
|
|
name: 'contMaintenance',
|
|
|
|
taskFunction: async () => {
|
|
|
|
this.actionStore.
|
|
|
|
await this.runMaintenance();
|
|
|
|
}
|
|
|
|
}), '0 0 * * * *');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* adds a bobcat to the manager
|
|
|
|
* @param networkAddressArg
|
|
|
|
*/
|
|
|
|
public async addBobcat (networkAddressArg: string) {
|
2022-02-25 19:36:44 +00:00
|
|
|
const newBobcat = await Bobcat.createFromNetworkAddress(networkAddressArg);
|
|
|
|
this.bobcats.push(newBobcat);
|
2022-02-25 21:45:11 +00:00
|
|
|
console.log(`added ${newBobcat.latestMinerDetails.animal} at ${newBobcat.networkAddress}`);
|
2022-02-25 19:36:44 +00:00
|
|
|
}
|
2022-02-25 20:33:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* runs the maintenance on all managed bobcats
|
|
|
|
*/
|
2022-02-27 18:10:44 +00:00
|
|
|
public async runMaintenance () {
|
2022-02-25 20:33:24 +00:00
|
|
|
console.log(`now running maintenance on ${this.bobcats.length} bobcats!`);
|
2022-02-25 21:45:11 +00:00
|
|
|
console.log(`cooling down for 10 seconds`);
|
|
|
|
await plugins.smartdelay.delayFor(10000);
|
2022-02-25 20:33:24 +00:00
|
|
|
for (const bobcat of this.bobcats) {
|
2022-02-25 21:45:11 +00:00
|
|
|
console.log(`now running maintenance on ${bobcat.latestMinerDetails.animal} at ${bobcat.networkAddress}`);
|
2022-02-25 20:33:24 +00:00
|
|
|
await bobcat.runMaintenance();
|
|
|
|
}
|
|
|
|
};
|
2022-02-27 18:10:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* starts continuous maintenance of the bobcat miners
|
|
|
|
*/
|
|
|
|
public async startTaskmanager () {
|
|
|
|
this.taskmanager.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stops the taskmanager
|
|
|
|
*/
|
|
|
|
public async stopTaskmanager () {
|
|
|
|
this.taskmanager.stop();
|
|
|
|
}
|
2022-02-24 19:16:21 +00:00
|
|
|
}
|