update
This commit is contained in:
@@ -6,12 +6,18 @@ import * as interfaces from './interfaces';
|
||||
*/
|
||||
export class Bobcat {
|
||||
// STATIC
|
||||
public static async createFromNetworkAddress(networkAddressArg: string) {
|
||||
public static minerAuthObject = {
|
||||
headers: {
|
||||
Authorization: 'Basic ' + Buffer.from('bobcat:miner').toString('base64')
|
||||
}
|
||||
}
|
||||
|
||||
public static async createFromNetworkAddress (networkAddressArg: string) {
|
||||
const newBobcat = new Bobcat(networkAddressArg);
|
||||
try {
|
||||
await newBobcat.checkMinerStatus();
|
||||
await newBobcat.gatherMinerDetails();
|
||||
} catch(err) {
|
||||
} catch (err) {
|
||||
console.log('initial adding completed with errors');
|
||||
}
|
||||
return newBobcat;
|
||||
@@ -30,7 +36,7 @@ export class Bobcat {
|
||||
/**
|
||||
* checks the status of the miner
|
||||
*/
|
||||
public async checkMinerStatus() {
|
||||
public async checkMinerStatus () {
|
||||
const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/status.json`, {
|
||||
timeout: 30000
|
||||
});
|
||||
@@ -42,7 +48,7 @@ export class Bobcat {
|
||||
/**
|
||||
* gathers the miner details
|
||||
*/
|
||||
public async gatherMinerDetails() {
|
||||
public async gatherMinerDetails () {
|
||||
const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/miner.json`, {
|
||||
timeout: 30000
|
||||
});
|
||||
@@ -54,16 +60,18 @@ export class Bobcat {
|
||||
/**
|
||||
* runs maintenance on the bobcat
|
||||
*/
|
||||
public async runMaintenance() {
|
||||
public async runMaintenance () {
|
||||
await this.checkMinerStatus();
|
||||
await this.gatherMinerDetails();
|
||||
if (this.latestStatus.status === 'Synced') {
|
||||
if (this.latestStatus.status === 'Synced' && parseInt(this.latestStatus.gap) > -50 && parseInt(this.latestStatus.gap) < 50) {
|
||||
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!`)
|
||||
console.log(
|
||||
`Miner ${this.latestMinerDetails.animal} at ${this.networkAddress} is Syncing... ok!`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -77,15 +85,26 @@ export class Bobcat {
|
||||
}
|
||||
}
|
||||
|
||||
public async restart() {
|
||||
/**
|
||||
* triggers a fast resync
|
||||
*/
|
||||
public async triggerFastResync() {
|
||||
const response = await plugins.smartrequest.request(`http://${this.networkAddress}/admin/fastsync`, {
|
||||
method: 'POST',
|
||||
...Bobcat.minerAuthObject
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* restarts the miner
|
||||
*/
|
||||
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
|
||||
timeout: 30000,
|
||||
...Bobcat.minerAuthObject
|
||||
});
|
||||
console.log(response.statusCode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user