mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-10 01:06:17 +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> {
|
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}"`)
|
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, {
|
const elementResult = await waitForElementSmart(page, selector, {
|
||||||
initialTimeoutMs: 2000,
|
initialTimeoutMs: 1000,
|
||||||
extendedTimeoutMs: TIMEOUTS.NETWORK_IDLE,
|
extendedTimeoutMs: 3000,
|
||||||
state: 'attached',
|
state: 'attached',
|
||||||
logFn: (msg) => this.bot.log(this.bot.isMobile, 'ACTIVITY', msg)
|
logFn: (msg) => this.bot.log(this.bot.isMobile, 'ACTIVITY', msg)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!elementResult.found) {
|
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
|
return // Skip this activity gracefully
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,9 +134,7 @@ export async function waitForElementSmart(
|
|||||||
return { found: true, timeMs: elapsed, element }
|
return { found: true, timeMs: elapsed, element }
|
||||||
|
|
||||||
} catch (firstError) {
|
} catch (firstError) {
|
||||||
// Element not found quickly - try extended wait
|
// Element not found quickly - try extended wait (silent until result known)
|
||||||
logFn('Element not immediate, extending timeout...')
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const element = page.locator(selector)
|
const element = page.locator(selector)
|
||||||
await element.waitFor({ state, timeout: extendedTimeoutMs })
|
await element.waitFor({ state, timeout: extendedTimeoutMs })
|
||||||
@@ -147,8 +145,8 @@ export async function waitForElementSmart(
|
|||||||
|
|
||||||
} catch (extendedError) {
|
} catch (extendedError) {
|
||||||
const elapsed = Date.now() - startTime
|
const elapsed = Date.now() - startTime
|
||||||
const errorMsg = extendedError instanceof Error ? extendedError.message : String(extendedError)
|
// IMPROVED: Concise failure message without full Playwright error stack
|
||||||
logFn(`✗ Element not found after ${elapsed}ms: ${errorMsg}`)
|
logFn(`Element not found after ${elapsed}ms (expected if activity unavailable)`)
|
||||||
return { found: false, timeMs: elapsed, element: null }
|
return { found: false, timeMs: elapsed, element: null }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user