Keep bot jobs and harness calls from hanging
This commit is contained in:
@@ -2,12 +2,38 @@ import { AppData } from "@/src/data/app-data";
|
||||
import dockerRequest from "./docker-request";
|
||||
import grabAppContainer from "./grab-app-container";
|
||||
|
||||
/**
|
||||
* Docker can still be coming up when the app container starts (a host
|
||||
* reboot, especially), so a transient failure is retried before the app
|
||||
* gives up on networking.
|
||||
*/
|
||||
const Attempts = 3;
|
||||
const RetryMs = 2000;
|
||||
|
||||
/**
|
||||
* Makes sure the network computers run on (`AppData.DockerNetworkName`)
|
||||
* exists and, when the app runs in docker, that its container is on it,
|
||||
* so it reaches computers by name.
|
||||
*/
|
||||
export default async function ensureDockerNetwork() {
|
||||
let last_error: unknown;
|
||||
|
||||
for (let attempt = 1; attempt <= Attempts; attempt++) {
|
||||
try {
|
||||
return await connectNetwork();
|
||||
} catch (error: unknown) {
|
||||
last_error = error;
|
||||
|
||||
if (attempt < Attempts) {
|
||||
await new Promise((resolve) => setTimeout(resolve, RetryMs));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw last_error;
|
||||
}
|
||||
|
||||
async function connectNetwork() {
|
||||
const name = AppData.DockerNetworkName;
|
||||
const existing = await dockerRequest({ path: `/networks/${encodeURIComponent(name)}` });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user