mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-09 17:06:15 +00:00
fix: Improve activity management by replacing fixed delay with fast failure for unavailable activities
This commit is contained in:
@@ -248,16 +248,16 @@ export class Workers {
|
||||
private async executeActivity(page: Page, activity: PromotionalItem | MorePromotion, selector: string, throttle: AdaptiveThrottler, retry: Retry): Promise<void> {
|
||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Found activity type: "${this.bot.activities.getTypeLabel(activity)}" title: "${activity.title}"`)
|
||||
|
||||
// IMPROVED: Smart wait replaces fixed 5s timeout with adaptive 2s+5s detection
|
||||
// IMPROVED: Fast-fail for unavailable activities (1s+3s instead of 2s+5s)
|
||||
const elementResult = await waitForElementSmart(page, selector, {
|
||||
initialTimeoutMs: 2000,
|
||||
extendedTimeoutMs: TIMEOUTS.NETWORK_IDLE,
|
||||
initialTimeoutMs: 1000,
|
||||
extendedTimeoutMs: 3000,
|
||||
state: 'attached',
|
||||
logFn: (msg) => this.bot.log(this.bot.isMobile, 'ACTIVITY', msg)
|
||||
})
|
||||
|
||||
if (!elementResult.found) {
|
||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Activity selector not found (might be completed or unavailable): ${selector}`, 'warn')
|
||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `[SKIP] Activity not available: "${activity.title}" (already completed or not offered today)`)
|
||||
return // Skip this activity gracefully
|
||||
}
|
||||
|
||||
|
||||
@@ -134,9 +134,7 @@ export async function waitForElementSmart(
|
||||
return { found: true, timeMs: elapsed, element }
|
||||
|
||||
} catch (firstError) {
|
||||
// Element not found quickly - try extended wait
|
||||
logFn('Element not immediate, extending timeout...')
|
||||
|
||||
// Element not found quickly - try extended wait (silent until result known)
|
||||
try {
|
||||
const element = page.locator(selector)
|
||||
await element.waitFor({ state, timeout: extendedTimeoutMs })
|
||||
@@ -147,8 +145,8 @@ export async function waitForElementSmart(
|
||||
|
||||
} catch (extendedError) {
|
||||
const elapsed = Date.now() - startTime
|
||||
const errorMsg = extendedError instanceof Error ? extendedError.message : String(extendedError)
|
||||
logFn(`✗ Element not found after ${elapsed}ms: ${errorMsg}`)
|
||||
// IMPROVED: Concise failure message without full Playwright error stack
|
||||
logFn(`Element not found after ${elapsed}ms (expected if activity unavailable)`)
|
||||
return { found: false, timeMs: elapsed, element: null }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user