Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
a9ff2e2ddc | |||
812a43449d | |||
806de97d22 | |||
5ab8115b34 | |||
d761b1459d | |||
26f0ac0508 | |||
efa5982dc9 | |||
db8f587d8d | |||
cbc3334994 | |||
d111e3709b | |||
66a8610bb1 | |||
e4c41b82ef | |||
47df20fd7e | |||
2182f51e09 | |||
35e4f129df | |||
c579f0d87f | |||
830fa7176d |
18
package-lock.json
generated
18
package-lock.json
generated
@ -1,16 +1,17 @@
|
||||
{
|
||||
"name": "@mojoio/bobcat",
|
||||
"version": "1.0.13",
|
||||
"version": "1.0.23",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@mojoio/bobcat",
|
||||
"version": "1.0.13",
|
||||
"version": "1.0.23",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdelay": "^2.0.13",
|
||||
"@pushrocks/smartnetwork": "^2.0.14",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@pushrocks/smartrequest": "^1.1.56",
|
||||
"@pushrocks/taskbuffer": "^2.1.17"
|
||||
},
|
||||
@ -2794,10 +2795,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@pushrocks/smartpromise": {
|
||||
"version": "3.1.6",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.1.6.tgz",
|
||||
"integrity": "sha512-v+RyVpspzYuBcV/aWXqwC03TWYeFLj7aWMG3IBDFmH2ssgug+82KLW/gw2WB2aVOEvmSkfI9OVvOQz2OsLbYlA==",
|
||||
"license": "MIT"
|
||||
"version": "3.1.7",
|
||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartpromise/-/smartpromise-3.1.7.tgz",
|
||||
"integrity": "sha512-2gLQCeviEJwZ+cHHtK2Ks98brZatGC6dPXKIs1tVgJsiNgRFjnp90fESuJ1Pmoe7RrS+7J3mO4NtsFHAJJ/y5w=="
|
||||
},
|
||||
"node_modules/@pushrocks/smartpuppeteer": {
|
||||
"version": "1.0.36",
|
||||
@ -17854,9 +17854,9 @@
|
||||
}
|
||||
},
|
||||
"@pushrocks/smartpromise": {
|
||||
"version": "3.1.6",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.1.6.tgz",
|
||||
"integrity": "sha512-v+RyVpspzYuBcV/aWXqwC03TWYeFLj7aWMG3IBDFmH2ssgug+82KLW/gw2WB2aVOEvmSkfI9OVvOQz2OsLbYlA=="
|
||||
"version": "3.1.7",
|
||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartpromise/-/smartpromise-3.1.7.tgz",
|
||||
"integrity": "sha512-2gLQCeviEJwZ+cHHtK2Ks98brZatGC6dPXKIs1tVgJsiNgRFjnp90fESuJ1Pmoe7RrS+7J3mO4NtsFHAJJ/y5w=="
|
||||
},
|
||||
"@pushrocks/smartpuppeteer": {
|
||||
"version": "1.0.36",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@mojoio/bobcat",
|
||||
"version": "1.0.13",
|
||||
"version": "1.0.23",
|
||||
"private": false,
|
||||
"description": "a module to talk to bobcat miners",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -39,6 +39,7 @@
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdelay": "^2.0.13",
|
||||
"@pushrocks/smartnetwork": "^2.0.14",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@pushrocks/smartrequest": "^1.1.56",
|
||||
"@pushrocks/taskbuffer": "^2.1.17"
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ export class Bobcat {
|
||||
public static async createFromNetworkAddress (networkAddressArg: string) {
|
||||
const newBobcat = new Bobcat(networkAddressArg);
|
||||
try {
|
||||
await newBobcat.checkMinerStatus();
|
||||
await newBobcat.gatherMinerDetails();
|
||||
await plugins.smartpromise.timeoutAndContinue(newBobcat.checkMinerStatus());
|
||||
await plugins.smartpromise.timeoutAndContinue(newBobcat.gatherMinerDetails());
|
||||
} catch (err) {
|
||||
console.log('initial adding completed with errors');
|
||||
}
|
||||
@ -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,15 @@ 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());
|
||||
await plugins.smartdelay.delayFor(10000);
|
||||
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 +84,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 +122,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);
|
||||
|
@ -20,10 +20,19 @@ export class BobcatManager {
|
||||
this.taskmanager.addAndScheduleTask(new plugins.taskbuffer.Task({
|
||||
name: 'contMaintenance',
|
||||
taskFunction: async () => {
|
||||
this.actionStore.
|
||||
this.actionStore.push();
|
||||
await this.runMaintenance();
|
||||
}
|
||||
}), '0 0 * * * *');
|
||||
this.taskmanager.addAndScheduleTask(new plugins.taskbuffer.Task({
|
||||
name: 'contStatus',
|
||||
taskFunction: async () => {
|
||||
this.actionStore.push();
|
||||
for (const bobcat of this.bobcats) {
|
||||
bobcat.checkMinerStatus();
|
||||
};
|
||||
}
|
||||
}), '0 * * * * *');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -33,7 +42,7 @@ export class BobcatManager {
|
||||
public async addBobcat (networkAddressArg: string) {
|
||||
const newBobcat = await Bobcat.createFromNetworkAddress(networkAddressArg);
|
||||
this.bobcats.push(newBobcat);
|
||||
console.log(`added ${newBobcat.latestMinerDetails.animal} at ${newBobcat.networkAddress}`);
|
||||
console.log(`added ${newBobcat.latestMinerDetails?.animal} at ${newBobcat.networkAddress}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,8 +53,8 @@ export class BobcatManager {
|
||||
console.log(`cooling down for 10 seconds`);
|
||||
await plugins.smartdelay.delayFor(10000);
|
||||
for (const bobcat of this.bobcats) {
|
||||
console.log(`now running maintenance on ${bobcat.latestMinerDetails.animal} at ${bobcat.networkAddress}`);
|
||||
await bobcat.runMaintenance();
|
||||
console.log(`now running maintenance on ${bobcat.latestMinerDetails?.animal} at ${bobcat.networkAddress}`);
|
||||
await plugins.smartpromise.timeoutAndContinue(bobcat.runMaintenance());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartnetwork from '@pushrocks/smartnetwork';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as taskbuffer from '@pushrocks/taskbuffer';
|
||||
|
||||
export {
|
||||
smartdelay,
|
||||
smartnetwork,
|
||||
smartpromise,
|
||||
smartrequest,
|
||||
taskbuffer,
|
||||
}
|
||||
|
Reference in New Issue
Block a user