This commit is contained in:
Philipp Kunz 2022-02-25 21:45:11 +00:00
parent 5fb5979c91
commit 99fa906630
5 changed files with 36 additions and 9 deletions

8
package-lock.json generated
View File

@ -9,6 +9,7 @@
"version": "1.0.12", "version": "1.0.12",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartnetwork": "^2.0.14", "@pushrocks/smartnetwork": "^2.0.14",
"@pushrocks/smartrequest": "^1.1.56" "@pushrocks/smartrequest": "^1.1.56"
}, },
@ -2459,10 +2460,8 @@
}, },
"node_modules/@pushrocks/smartdelay": { "node_modules/@pushrocks/smartdelay": {
"version": "2.0.13", "version": "2.0.13",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartdelay/-/smartdelay-2.0.13.tgz", "resolved": "https://registry.npmjs.org/@pushrocks/smartdelay/-/smartdelay-2.0.13.tgz",
"integrity": "sha512-s6Wh0BHWMfZ5VYONQwpxOYX1JeC9RKA0O9TxEzfZ6FCw2oNQb2QUPCixT9rsceKwva4+atKRw/RfU+Z7aJDmsA==", "integrity": "sha512-s6Wh0BHWMfZ5VYONQwpxOYX1JeC9RKA0O9TxEzfZ6FCw2oNQb2QUPCixT9rsceKwva4+atKRw/RfU+Z7aJDmsA==",
"dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"@pushrocks/smartpromise": "^3.0.6" "@pushrocks/smartpromise": "^3.0.6"
} }
@ -17522,9 +17521,8 @@
}, },
"@pushrocks/smartdelay": { "@pushrocks/smartdelay": {
"version": "2.0.13", "version": "2.0.13",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartdelay/-/smartdelay-2.0.13.tgz", "resolved": "https://registry.npmjs.org/@pushrocks/smartdelay/-/smartdelay-2.0.13.tgz",
"integrity": "sha512-s6Wh0BHWMfZ5VYONQwpxOYX1JeC9RKA0O9TxEzfZ6FCw2oNQb2QUPCixT9rsceKwva4+atKRw/RfU+Z7aJDmsA==", "integrity": "sha512-s6Wh0BHWMfZ5VYONQwpxOYX1JeC9RKA0O9TxEzfZ6FCw2oNQb2QUPCixT9rsceKwva4+atKRw/RfU+Z7aJDmsA==",
"dev": true,
"requires": { "requires": {
"@pushrocks/smartpromise": "^3.0.6" "@pushrocks/smartpromise": "^3.0.6"
} }

View File

@ -37,6 +37,7 @@
"readme.md" "readme.md"
], ],
"dependencies": { "dependencies": {
"@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartnetwork": "^2.0.14", "@pushrocks/smartnetwork": "^2.0.14",
"@pushrocks/smartrequest": "^1.1.56" "@pushrocks/smartrequest": "^1.1.56"
} }

View File

@ -23,6 +23,7 @@ export class Bobcat {
public latestMinerDetails: interfaces.IMinerDetailsResponse public latestMinerDetails: interfaces.IMinerDetailsResponse
constructor(networkAddressArg: string) { constructor(networkAddressArg: string) {
console.log(`adding bobcat at ${networkAddressArg}`);
this.networkAddress = networkAddressArg; this.networkAddress = networkAddressArg;
} }
@ -30,7 +31,9 @@ export class Bobcat {
* checks the status of the miner * checks the status of the miner
*/ */
public async checkMinerStatus() { public async checkMinerStatus() {
const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/status.json`); const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/status.json`, {
timeout: 30000
});
const body: interfaces.IMinerStatus = response.body; const body: interfaces.IMinerStatus = response.body;
this.latestStatus = body; this.latestStatus = body;
return this.latestStatus; return this.latestStatus;
@ -40,7 +43,9 @@ export class Bobcat {
* gathers the miner details * gathers the miner details
*/ */
public async gatherMinerDetails() { public async gatherMinerDetails() {
const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/miner.json`); const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/miner.json`, {
timeout: 30000
});
const body: interfaces.IMinerDetailsResponse = response.body; const body: interfaces.IMinerDetailsResponse = response.body;
this.latestMinerDetails = body; this.latestMinerDetails = body;
return this.latestMinerDetails; return this.latestMinerDetails;
@ -52,18 +57,35 @@ export class Bobcat {
public async runMaintenance() { public async runMaintenance() {
await this.checkMinerStatus(); await this.checkMinerStatus();
await this.gatherMinerDetails(); await this.gatherMinerDetails();
if (this.latestStatus.status === 'Synced') {
console.log(`Miner ${this.latestMinerDetails.animal} at ${this.networkAddress} is Synced. ok!`)
return;
}
if (this.latestStatus.status === 'Syncing') {
console.log(`Miner ${this.latestMinerDetails.animal} at ${this.networkAddress} is Syncing... ok!`)
return;
}
if (this.latestStatus.status !== 'Synced') { if (this.latestStatus.status !== 'Synced') {
console.log(`Miner ${this.latestMinerDetails.animal} is not synced. Restarting now!`); console.log(`Miner ${this.latestMinerDetails.animal} is not synced. Restarting now!`);
await this.restart().catch(); try {
await this.restart()
} catch (err) {
}
} }
} }
public async restart() { public async restart() {
console.log(`cooling down before restart`);
await plugins.smartdelay.delayFor(10000);
const response = await plugins.smartrequest.request(`http://${this.networkAddress}/admin/reboot`, { const response = await plugins.smartrequest.request(`http://${this.networkAddress}/admin/reboot`, {
method: 'POST', method: 'POST',
headers: { headers: {
Authorization: 'Basic ' + Buffer.from('bobcat:miner').toString('base64') Authorization: 'Basic ' + Buffer.from('bobcat:miner').toString('base64')
} },
timeout: 30000
}); });
console.log(response.statusCode); console.log(response.statusCode);
} }

View File

@ -10,6 +10,7 @@ export class BobcatManager {
public async addBobcat(networkAddressArg: string) { public async addBobcat(networkAddressArg: string) {
const newBobcat = await Bobcat.createFromNetworkAddress(networkAddressArg); const newBobcat = await Bobcat.createFromNetworkAddress(networkAddressArg);
this.bobcats.push(newBobcat); this.bobcats.push(newBobcat);
console.log(`added ${newBobcat.latestMinerDetails.animal} at ${newBobcat.networkAddress}`);
} }
/** /**
@ -17,7 +18,10 @@ export class BobcatManager {
*/ */
public async runMaintenance() { public async runMaintenance() {
console.log(`now running maintenance on ${this.bobcats.length} bobcats!`); console.log(`now running maintenance on ${this.bobcats.length} bobcats!`);
console.log(`cooling down for 10 seconds`);
await plugins.smartdelay.delayFor(10000);
for (const bobcat of this.bobcats) { for (const bobcat of this.bobcats) {
console.log(`now running maintenance on ${bobcat.latestMinerDetails.animal} at ${bobcat.networkAddress}`);
await bobcat.runMaintenance(); await bobcat.runMaintenance();
} }
}; };

View File

@ -1,7 +1,9 @@
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartnetwork from '@pushrocks/smartnetwork'; import * as smartnetwork from '@pushrocks/smartnetwork';
import * as smartrequest from '@pushrocks/smartrequest'; import * as smartrequest from '@pushrocks/smartrequest';
export { export {
smartdelay,
smartnetwork, smartnetwork,
smartrequest smartrequest
} }