update
This commit is contained in:
@@ -23,6 +23,7 @@ export class Bobcat {
|
||||
public latestMinerDetails: interfaces.IMinerDetailsResponse
|
||||
|
||||
constructor(networkAddressArg: string) {
|
||||
console.log(`adding bobcat at ${networkAddressArg}`);
|
||||
this.networkAddress = networkAddressArg;
|
||||
}
|
||||
|
||||
@@ -30,7 +31,9 @@ export class Bobcat {
|
||||
* checks the status of the miner
|
||||
*/
|
||||
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;
|
||||
this.latestStatus = body;
|
||||
return this.latestStatus;
|
||||
@@ -40,7 +43,9 @@ export class Bobcat {
|
||||
* gathers the miner details
|
||||
*/
|
||||
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;
|
||||
this.latestMinerDetails = body;
|
||||
return this.latestMinerDetails;
|
||||
@@ -52,18 +57,35 @@ export class Bobcat {
|
||||
public async runMaintenance() {
|
||||
await this.checkMinerStatus();
|
||||
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') {
|
||||
console.log(`Miner ${this.latestMinerDetails.animal} is not synced. Restarting now!`);
|
||||
await this.restart().catch();
|
||||
try {
|
||||
await this.restart()
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: 'Basic ' + Buffer.from('bobcat:miner').toString('base64')
|
||||
}
|
||||
},
|
||||
timeout: 30000
|
||||
});
|
||||
console.log(response.statusCode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user