Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion scripts/api/logParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export function createRunState() {
order: [], // emails in the order they started
accounts: {}, // email -> account summary
errors: [], // recent error/warn messages { ts, level, title, message }
finished: false
finished: false,
pendingDelay: null // { seconds, nextEmail, sinceTs } while waiting between accounts/workers
}
}

Expand Down Expand Up @@ -102,6 +103,11 @@ const RE = {
runEnd: /^Completed all accounts \| accountsProcessed=(\d+) \| pointsGained=(-?\d+) \| previousBalance=(\d+) \| currentBalance=(\d+) \| runtimeMinutes=([\d.]+)/,
accountError: /^(\S+@\S+): ([\s\S]+)$/,
flowFailed: /flow failed for (\S+@\S+):/i,
// index.ts's waitBeforeNextAccount() appends the upcoming account's email
// in parentheses when it's known (it always is, on both the single-worker
// and cluster-fork paths). The email is optional in the regex only to
// stay forward-compatible with older/foreign log lines that lack it.
accountDelay: /^Waiting ([\d.]+) seconds before starting the next account(?: \((\S+@\S+)\))?$/,

searchStart: /^Starting Bing searches \| currentBalance=(\d+)/,
flowCollected: /^Points collected \| pointsGained=(-?\d+) \| currentBalance=(\d+) \| account=(\S+@\S+)/
Expand Down Expand Up @@ -242,6 +248,7 @@ export function applyLogToRunState(state, entry) {
state.accountsTotal = Number(m[2])
state.clusters = Number(m[3])
state.finished = false
state.pendingDelay = null
return 'run-start'
}
break
Expand All @@ -252,10 +259,22 @@ export function applyLogToRunState(state, entry) {
if (acc) acc.geoLocale = m[2]
state.currentEmail = m[1]
if (entry.user) state.userToEmail[entry.user] = m[1] // map localpart -> full email
state.pendingDelay = null
return 'account-start'
}
break

case 'ACCOUNT-DELAY':
if ((m = msg.match(RE.accountDelay))) {
state.pendingDelay = {
seconds: Number(m[1]),
nextEmail: m[2] || null,
sinceTs: entry.ts
}
return 'account-delay'
}
break

case 'POINTS':
if ((m = msg.match(RE.earnable))) {
const email = m[4]
Expand Down Expand Up @@ -333,6 +352,7 @@ export function applyLogToRunState(state, entry) {
runtimeMinutes: Number(m[5])
}
state.finished = true
state.pendingDelay = null
return 'run-end'
}
break
Expand Down Expand Up @@ -367,6 +387,7 @@ export function summarizeRunState(state) {
collected,
totals: state.totals,
finished: state.finished,
pendingDelay: state.pendingDelay,
live: {
currentAccount: state.currentEmail,
currentBalance: current?.live?.balance ?? null,
Expand Down
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export class MicrosoftRewardsBot {

for (const [chunkIndex, chunk] of accountChunks.entries()) {
if (chunkIndex > 0) {
await this.waitBeforeNextAccount()
await this.waitBeforeNextAccount(chunk[0]?.email)
}

const worker = cluster.fork()
Expand Down Expand Up @@ -397,7 +397,7 @@ export class MicrosoftRewardsBot {

for (const [accountIndex, account] of accounts.entries()) {
if (accountIndex > 0) {
await this.waitBeforeNextAccount()
await this.waitBeforeNextAccount(account.email)
}

const accountStartTime = Date.now()
Expand Down Expand Up @@ -508,7 +508,7 @@ export class MicrosoftRewardsBot {
return accountStats
}

private async waitBeforeNextAccount(): Promise<void> {
private async waitBeforeNextAccount(nextEmail?: string): Promise<void> {
const { min, max } = this.config.accountDelay
const minMs = typeof min === 'number' ? min : this.utils.stringToNumber(min)
const maxMs = typeof max === 'number' ? max : this.utils.stringToNumber(max)
Expand All @@ -521,7 +521,9 @@ export class MicrosoftRewardsBot {
this.logger.info(
'main',
'ACCOUNT-DELAY',
`Waiting ${(delayMs / 1000).toFixed(1)} seconds before starting the next account`
`Waiting ${(delayMs / 1000).toFixed(1)} seconds before starting the next account${
nextEmail ? ` (${nextEmail})` : ''
}`
)
await this.utils.wait(delayMs)
}
Expand Down