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`);
|
||||
|
||||
while (!this.cancelled) {
|
||||
try {
|
||||
// Safety checks
|
||||
const fuel = await this.checkFuel();
|
||||
if (fuel !== 'unlimited' && fuel < this.minFuel) {
|
||||
@@ -82,6 +83,16 @@ export class MiningState extends BaseState {
|
||||
// Explore step - try to find new areas
|
||||
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;
|
||||
await this._sleep(200);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user