|
|
|
@ -38,7 +38,7 @@ export class Bobcat {
|
|
|
|
|
*/
|
|
|
|
|
public async checkMinerStatus () {
|
|
|
|
|
const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/status.json`, {
|
|
|
|
|
timeout: 30000
|
|
|
|
|
timeout: 60000
|
|
|
|
|
});
|
|
|
|
|
const body: interfaces.IMinerStatus = response.body;
|
|
|
|
|
this.latestStatus = body;
|
|
|
|
@ -50,7 +50,7 @@ export class Bobcat {
|
|
|
|
|
*/
|
|
|
|
|
public async gatherMinerDetails () {
|
|
|
|
|
const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/miner.json`, {
|
|
|
|
|
timeout: 30000
|
|
|
|
|
timeout: 60000
|
|
|
|
|
});
|
|
|
|
|
const body: interfaces.IMinerDetailsResponse = response.body;
|
|
|
|
|
this.latestMinerDetails = body;
|
|
|
|
@ -61,9 +61,14 @@ export class Bobcat {
|
|
|
|
|
* runs maintenance on the bobcat
|
|
|
|
|
*/
|
|
|
|
|
public async runMaintenance () {
|
|
|
|
|
await this.checkMinerStatus();
|
|
|
|
|
await this.gatherMinerDetails();
|
|
|
|
|
if (this.latestStatus.status === 'Synced' && parseInt(this.latestStatus.gap) > -50 && parseInt(this.latestStatus.gap) < 50) {
|
|
|
|
|
await plugins.smartpromise.timeoutAndContinue(this.checkMinerStatus());
|
|
|
|
|
await plugins.smartdelay.delayFor(10000);
|
|
|
|
|
await plugins.smartpromise.timeoutAndContinue(this.gatherMinerDetails());
|
|
|
|
|
await plugins.smartdelay.delayFor(10000);
|
|
|
|
|
await plugins.smartpromise.timeoutAndContinue(this.checkMinerStatus());
|
|
|
|
|
await plugins.smartdelay.delayFor(10000);
|
|
|
|
|
await plugins.smartpromise.timeoutAndContinue(this.gatherMinerDetails());
|
|
|
|
|
if (this.latestStatus.status === 'Synced' && parseInt(this.latestStatus.gap) > -100 && parseInt(this.latestStatus.gap) < 50) {
|
|
|
|
|
console.log(`Miner ${this.latestMinerDetails.animal} at ${this.networkAddress} is Synced. ok!`)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -78,11 +83,24 @@ export class Bobcat {
|
|
|
|
|
if (this.latestStatus.status !== 'Synced') {
|
|
|
|
|
console.log(`Miner ${this.latestMinerDetails.animal} is not synced. Restarting now!`);
|
|
|
|
|
try {
|
|
|
|
|
await this.restart()
|
|
|
|
|
await this.restart();
|
|
|
|
|
return;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.latestStatus.status === 'Synced' && parseInt(this.latestStatus.gap) < -100) {
|
|
|
|
|
console.log(`Miner ${this.latestMinerDetails.animal} is Synced, but strangely ahead of blockchain. Restarting!`);
|
|
|
|
|
try {
|
|
|
|
|
await this.restart();
|
|
|
|
|
return;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(`Looks like miner ${this.latestMinerDetails.animal} is Synced, but does not fall under predefined statuses!`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -103,7 +121,7 @@ export class Bobcat {
|
|
|
|
|
await plugins.smartdelay.delayFor(10000);
|
|
|
|
|
const response = await plugins.smartrequest.request(`http://${this.networkAddress}/admin/reboot`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
timeout: 30000,
|
|
|
|
|
timeout: 60000,
|
|
|
|
|
...Bobcat.minerAuthObject
|
|
|
|
|
});
|
|
|
|
|
console.log(response.statusCode);
|
|
|
|
|