Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry #10

Merged
merged 1 commit into from
Jun 27, 2023
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
32 changes: 27 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 28 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@ import { spawn } from 'node:child_process';
import { createWriteStream, openSync, writeSync, close } from 'node:fs';
import { pipeline } from 'node:stream/promises';
import { setTimeout } from 'timers/promises';
import { inspect } from 'node:util';

import * as core from '@actions/core';
import { Tail } from 'tail';
import got from "got";

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 {
const runnerArch = process.env.RUNNER_ARCH;
const runnerOs = process.env.RUNNER_OS;
Expand Down Expand Up @@ -53,7 +69,7 @@ async function fetchAutoCacher(destination: string) {
core.debug(`Fetching the Magic Nix Cache from ${binary_url}`);

return pipeline(
got.stream(binary_url),
gotClient.stream(binary_url),
stream
);
}
Expand Down Expand Up @@ -141,8 +157,16 @@ async function notifyAutoCache() {
return;
}

const res: any = await got.post(`http://${core.getInput('listen')}/api/workflow-start`).json();
core.debug(res);
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);
} 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() {
Expand Down Expand Up @@ -170,7 +194,7 @@ async function tearDownAutoCache() {

try {
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(res);
} finally {
Expand Down