Skip to content

Commit

Permalink
Smarter sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterbrandsen committed Feb 12, 2024
1 parent e503729 commit 124903e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
15 changes: 15 additions & 0 deletions files/defaultActions.unknown.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,20 @@
"path": "countByType.intents.rangedHeal",
"value": 0,
"type": 0
},
{
"path": "countByType.creepParts.tough",
"value": 0,
"type": 1
},
{
"path": "countByType.constructionSites.extension",
"value": 0,
"type": 1
},
{
"path": "countByType.constructionSites.storage",
"value": 0,
"type": 1
}
]
12 changes: 11 additions & 1 deletion src/process/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,18 @@ function shouldFail(opts) {
return true;
}

const lastRequest = {}
async function waitMax500ms(proxyIndex) {
const last = lastRequest[proxyIndex] || 0;
const diff = Date.now() - last;
if (diff < 500) {
return sleep(500 - diff);
}
return Promise.resolve();
}

export default async function processData(opts, proxyIndex) {
await sleep(500)
await waitMax500ms(proxyIndex);
let proxy = null;
if (proxyIndex !== undefined) {
proxy = await getProxy(proxyIndex);
Expand Down
1 change: 1 addition & 0 deletions src/requests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class Requests {
for (let i = cycleLength - 1; i >= 0; i -= 1) {
const opts = cycle[i];
console.log(`${cycleLength - i} / ${cycleLength} of cycle ${opts.shard}/${opts.tick}`)
await sleep(500)
await processOpts(opts, undefined);
}
}
Expand Down

0 comments on commit 124903e

Please sign in to comment.