refactor: streamline safety checks and error handling in mining operation for improved reliability
This commit is contained in:
@@ -40,6 +40,7 @@ export class MiningState extends BaseState {
|
|||||||
console.log(`[${this.turtle.id}] Starting mining operation`);
|
console.log(`[${this.turtle.id}] Starting mining operation`);
|
||||||
|
|
||||||
while (!this.cancelled) {
|
while (!this.cancelled) {
|
||||||
|
try {
|
||||||
// Safety checks
|
// Safety checks
|
||||||
const fuel = await this.checkFuel();
|
const fuel = await this.checkFuel();
|
||||||
if (fuel !== 'unlimited' && fuel < this.minFuel) {
|
if (fuel !== 'unlimited' && fuel < this.minFuel) {
|
||||||
@@ -82,6 +83,16 @@ export class MiningState extends BaseState {
|
|||||||
// Explore step - try to find new areas
|
// Explore step - try to find new areas
|
||||||
yield* this._exploreStep();
|
yield* this._exploreStep();
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
const isTimeout = error.message?.includes('timed out');
|
||||||
|
if (isTimeout) {
|
||||||
|
console.warn(`[${this.turtle.id}] Mining exec timeout, will retry next iteration`);
|
||||||
|
await this._sleep(3000);
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
yield;
|
yield;
|
||||||
await this._sleep(200);
|
await this._sleep(200);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user