fix: timeout calculation

This commit is contained in:
Ivan Dlugos 2022-04-12 10:12:56 +02:00
parent 3682b366b0
commit 989a39a417
2 changed files with 19 additions and 8 deletions

10
dist/index.js vendored
View file

@ -7019,7 +7019,7 @@ function run() {
else { else {
const waitTimeoutSeconds = parseInt(waitTimeoutStr); const waitTimeoutSeconds = parseInt(waitTimeoutStr);
runDownload = (action) => __awaiter(this, void 0, void 0, function* () { runDownload = (action) => __awaiter(this, void 0, void 0, function* () {
const waitUntil = new Date().getSeconds() + waitTimeoutSeconds; const waitUntil = Date.now() + waitTimeoutSeconds * 1000;
let lastError; let lastError;
do { do {
try { try {
@ -7027,11 +7027,13 @@ function run() {
} }
catch (e) { catch (e) {
lastError = e; lastError = e;
core.info('Waiting for the artifact to become available...'); core.info('Waiting for the artifact to become available... ' +
`Remaining time until timeout: ${Math.max(0, Math.floor((waitUntil - Date.now()) / 1000))} seconds`);
yield new Promise(f => setTimeout(f, 10000)); yield new Promise(f => setTimeout(f, 10000));
} }
} while (new Date().getSeconds() < waitUntil); } while (Date.now() < waitUntil);
throw Error('Timeout reached. Latest error: ' + lastError); throw Error('Waiting for the artifact has timed out. Latest error was: ' +
lastError);
}); });
} }
let resolvedPath; let resolvedPath;

View file

@ -17,18 +17,27 @@ async function run(): Promise<void> {
} else { } else {
const waitTimeoutSeconds = parseInt(waitTimeoutStr) const waitTimeoutSeconds = parseInt(waitTimeoutStr)
runDownload = async <T extends unknown>(action: () => T) => { runDownload = async <T extends unknown>(action: () => T) => {
const waitUntil = new Date().getSeconds() + waitTimeoutSeconds const waitUntil = Date.now() + waitTimeoutSeconds * 1000
let lastError let lastError
do { do {
try { try {
return await action() return await action()
} catch (e) { } catch (e) {
lastError = e lastError = e
core.info('Waiting for the artifact to become available...') core.info(
'Waiting for the artifact to become available... ' +
`Remaining time until timeout: ${Math.max(
0,
Math.floor((waitUntil - Date.now()) / 1000)
)} seconds`
)
await new Promise(f => setTimeout(f, 10000)) await new Promise(f => setTimeout(f, 10000))
} }
} while (new Date().getSeconds() < waitUntil) } while (Date.now() < waitUntil)
throw Error('Timeout reached. Latest error: ' + lastError) throw Error(
'Waiting for the artifact has timed out. Latest error was: ' +
lastError
)
} }
} }