mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-27 01:30:35 +01:00
Retry a few times on startup, but don't fail the run if we can't
This commit is contained in:
parent
a6e7fb2bde
commit
54ca4788d1
2 changed files with 55 additions and 9 deletions
30
dist/index.js
generated
vendored
30
dist/index.js
generated
vendored
|
@ -6,6 +6,7 @@ import { spawn } from 'node:child_process';
|
||||||
import { openSync, writeSync, close, createWriteStream } from 'node:fs';
|
import { openSync, writeSync, close, createWriteStream } from 'node:fs';
|
||||||
import { pipeline } from 'node:stream/promises';
|
import { pipeline } from 'node:stream/promises';
|
||||||
import { setTimeout as setTimeout$1 } from 'timers/promises';
|
import { setTimeout as setTimeout$1 } from 'timers/promises';
|
||||||
|
import { promisify as promisify$1, inspect } from 'node:util';
|
||||||
import require$$0 from 'os';
|
import require$$0 from 'os';
|
||||||
import require$$1 from 'fs';
|
import require$$1 from 'fs';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
|
@ -27,7 +28,6 @@ import crypto$1 from 'node:crypto';
|
||||||
import require$$0$4 from 'buffer';
|
import require$$0$4 from 'buffer';
|
||||||
import require$$0$3 from 'stream';
|
import require$$0$3 from 'stream';
|
||||||
import require$$1$3 from 'zlib';
|
import require$$1$3 from 'zlib';
|
||||||
import { promisify as promisify$1, inspect } from 'node:util';
|
|
||||||
import net from 'node:net';
|
import net from 'node:net';
|
||||||
import { checkServerIdentity } from 'node:tls';
|
import { checkServerIdentity } from 'node:tls';
|
||||||
import https$4 from 'node:https';
|
import https$4 from 'node:https';
|
||||||
|
@ -12103,6 +12103,19 @@ var got$1 = got;
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
const ENV_CACHE_DAEMONDIR = 'MAGIC_NIX_CACHE_DAEMONDIR';
|
const ENV_CACHE_DAEMONDIR = 'MAGIC_NIX_CACHE_DAEMONDIR';
|
||||||
|
const gotClient = got$1.extend({
|
||||||
|
retry: {
|
||||||
|
limit: 5,
|
||||||
|
methods: ['POST', 'GET', 'PUT', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE'],
|
||||||
|
},
|
||||||
|
hooks: {
|
||||||
|
beforeRetry: [
|
||||||
|
(error, retryCount) => {
|
||||||
|
coreExports.info(`Retrying after error ${error.code}, retry #: ${retryCount}`);
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
function getCacherUrl() {
|
function getCacherUrl() {
|
||||||
const runnerArch = process.env.RUNNER_ARCH;
|
const runnerArch = process.env.RUNNER_ARCH;
|
||||||
const runnerOs = process.env.RUNNER_OS;
|
const runnerOs = process.env.RUNNER_OS;
|
||||||
|
@ -12132,7 +12145,7 @@ async function fetchAutoCacher(destination) {
|
||||||
});
|
});
|
||||||
const binary_url = getCacherUrl();
|
const binary_url = getCacherUrl();
|
||||||
coreExports.debug(`Fetching the Magic Nix Cache from ${binary_url}`);
|
coreExports.debug(`Fetching the Magic Nix Cache from ${binary_url}`);
|
||||||
return pipeline(got$1.stream(binary_url), stream);
|
return pipeline(gotClient.stream(binary_url), stream);
|
||||||
}
|
}
|
||||||
async function setUpAutoCache() {
|
async function setUpAutoCache() {
|
||||||
const tmpdir = process.env['RUNNER_TEMP'] || os$2.tmpdir();
|
const tmpdir = process.env['RUNNER_TEMP'] || os$2.tmpdir();
|
||||||
|
@ -12204,8 +12217,17 @@ async function notifyAutoCache() {
|
||||||
if (!daemonDir) {
|
if (!daemonDir) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const res = await got$1.post(`http://${coreExports.getInput('listen')}/api/workflow-start`).json();
|
try {
|
||||||
|
coreExports.debug(`Indicating workflow start`);
|
||||||
|
const res = await gotClient.post(`http://${coreExports.getInput('listen')}/api/workflow-start`).json();
|
||||||
|
coreExports.debug(`back from post`);
|
||||||
coreExports.debug(res);
|
coreExports.debug(res);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
coreExports.info(`Error marking the workflow as started:`);
|
||||||
|
coreExports.info(inspect(e));
|
||||||
|
coreExports.info(`Magic Nix Cache may not be running for this workflow.`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
async function tearDownAutoCache() {
|
async function tearDownAutoCache() {
|
||||||
const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
||||||
|
@ -12227,7 +12249,7 @@ async function tearDownAutoCache() {
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
coreExports.debug(`about to post to localhost`);
|
coreExports.debug(`about to post to localhost`);
|
||||||
const res = await got$1.post(`http://${coreExports.getInput('listen')}/api/workflow-finish`).json();
|
const res = await gotClient.post(`http://${coreExports.getInput('listen')}/api/workflow-finish`).json();
|
||||||
coreExports.debug(`back from post`);
|
coreExports.debug(`back from post`);
|
||||||
coreExports.debug(res);
|
coreExports.debug(res);
|
||||||
}
|
}
|
||||||
|
|
30
src/index.ts
30
src/index.ts
|
@ -7,6 +7,7 @@ import { spawn } from 'node:child_process';
|
||||||
import { createWriteStream, openSync, writeSync, close } from 'node:fs';
|
import { createWriteStream, openSync, writeSync, close } from 'node:fs';
|
||||||
import { pipeline } from 'node:stream/promises';
|
import { pipeline } from 'node:stream/promises';
|
||||||
import { setTimeout } from 'timers/promises';
|
import { setTimeout } from 'timers/promises';
|
||||||
|
import { inspect } from 'node:util';
|
||||||
|
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import { Tail } from 'tail';
|
import { Tail } from 'tail';
|
||||||
|
@ -14,6 +15,21 @@ import got from "got";
|
||||||
|
|
||||||
const ENV_CACHE_DAEMONDIR = 'MAGIC_NIX_CACHE_DAEMONDIR';
|
const ENV_CACHE_DAEMONDIR = 'MAGIC_NIX_CACHE_DAEMONDIR';
|
||||||
|
|
||||||
|
const gotClient = got.extend({
|
||||||
|
retry: {
|
||||||
|
limit: 5,
|
||||||
|
methods: [ 'POST', 'GET', 'PUT', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE' ],
|
||||||
|
},
|
||||||
|
hooks: {
|
||||||
|
beforeRetry: [
|
||||||
|
(error, retryCount) => {
|
||||||
|
core.info(`Retrying after error ${error.code}, retry #: ${retryCount}`);
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
function getCacherUrl() : string {
|
function getCacherUrl() : string {
|
||||||
const runnerArch = process.env.RUNNER_ARCH;
|
const runnerArch = process.env.RUNNER_ARCH;
|
||||||
const runnerOs = process.env.RUNNER_OS;
|
const runnerOs = process.env.RUNNER_OS;
|
||||||
|
@ -53,7 +69,7 @@ async function fetchAutoCacher(destination: string) {
|
||||||
core.debug(`Fetching the Magic Nix Cache from ${binary_url}`);
|
core.debug(`Fetching the Magic Nix Cache from ${binary_url}`);
|
||||||
|
|
||||||
return pipeline(
|
return pipeline(
|
||||||
got.stream(binary_url),
|
gotClient.stream(binary_url),
|
||||||
stream
|
stream
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -141,8 +157,16 @@ async function notifyAutoCache() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res: any = await got.post(`http://${core.getInput('listen')}/api/workflow-start`).json();
|
try {
|
||||||
|
core.debug(`Indicating workflow start`);
|
||||||
|
const res: any = await gotClient.post(`http://${core.getInput('listen')}/api/workflow-start`).json();
|
||||||
|
core.debug(`back from post`);
|
||||||
core.debug(res);
|
core.debug(res);
|
||||||
|
} catch (e) {
|
||||||
|
core.info(`Error marking the workflow as started:`);
|
||||||
|
core.info(inspect(e));
|
||||||
|
core.info(`Magic Nix Cache may not be running for this workflow.`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function tearDownAutoCache() {
|
async function tearDownAutoCache() {
|
||||||
|
@ -170,7 +194,7 @@ async function tearDownAutoCache() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
core.debug(`about to post to localhost`);
|
core.debug(`about to post to localhost`);
|
||||||
const res: any = await got.post(`http://${core.getInput('listen')}/api/workflow-finish`).json();
|
const res: any = await gotClient.post(`http://${core.getInput('listen')}/api/workflow-finish`).json();
|
||||||
core.debug(`back from post`);
|
core.debug(`back from post`);
|
||||||
core.debug(res);
|
core.debug(res);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in a new issue