Skip to content

Commit

Permalink
chore: improve //utils/check_availability.js (#4770)
Browse files Browse the repository at this point in the history
This patch teaches `//utils/check_availability.js` to break
when it is run with no arguments and it finds an available revision.
  • Loading branch information
aslushnikov committed Jul 29, 2019
1 parent cc805e7 commit 3bbc45a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions utils/check_availability.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Running command without arguments will check against omahaproxy revisions.`);

const fromRevision = parseInt(process.argv[2], 10);
const toRevision = parseInt(process.argv[3], 10);
checkRangeAvailability(fromRevision, toRevision);
checkRangeAvailability(fromRevision, toRevision, false /* stopWhenAllAvailable */);

async function checkOmahaProxyAvailability() {
const lastchanged = (await Promise.all([
Expand All @@ -74,25 +74,30 @@ async function checkOmahaProxyAvailability() {
fetch('https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/LAST_CHANGE'),
])).map(s => parseInt(s, 10));
const from = Math.max(...lastchanged);
checkRangeAvailability(from, 0);
checkRangeAvailability(from, 0, true /* stopWhenAllAvailable */);
}

/**
* @param {number} fromRevision
* @param {number} toRevision
* @param {boolean} stopWhenAllAvailable
*/
async function checkRangeAvailability(fromRevision, toRevision) {
async function checkRangeAvailability(fromRevision, toRevision, stopWhenAllAvailable) {
const table = new Table([10, 7, 7, 7, 7]);
table.drawRow([''].concat(SUPPORTER_PLATFORMS));
const inc = fromRevision < toRevision ? 1 : -1;
for (let revision = fromRevision; revision !== toRevision; revision += inc)
await checkAndDrawRevisionAvailability(table, '', revision);
for (let revision = fromRevision; revision !== toRevision; revision += inc) {
const allAvailable = await checkAndDrawRevisionAvailability(table, '', revision);
if (allAvailable && stopWhenAllAvailable)
break;
}
}

/**
* @param {!Table} table
* @param {string} name
* @param {number} revision
* @return {boolean}
*/
async function checkAndDrawRevisionAvailability(table, name, revision) {
const promises = fetchers.map(fetcher => fetcher.canDownload(revision));
Expand All @@ -105,6 +110,7 @@ async function checkAndDrawRevisionAvailability(table, name, revision) {
values.push(color + decoration + colors.reset);
}
table.drawRow(values);
return allAvailable;
}

/**
Expand Down

0 comments on commit 3bbc45a

Please sign in to comment.