fix: release cooldown on pre-request failures
This commit is contained in:
@@ -88,7 +88,18 @@ function reserveCooldown(args) {
|
||||
if (result.stderr) process.stderr.write(result.stderr);
|
||||
throw new Error(`cooldown reservation failed with exit code ${result.status}`);
|
||||
}
|
||||
process.stdout.write(`${result.stdout.trim()}\n`);
|
||||
const reservation = JSON.parse(result.stdout);
|
||||
process.stdout.write(`${JSON.stringify(reservation)}\n`);
|
||||
return reservation;
|
||||
}
|
||||
|
||||
function releaseCooldown(args, reservation) {
|
||||
if (!reservation?.reserved_at) return;
|
||||
const source = args.mode === "catalog" ? "rf4db-waterbodies" : "rf4db-waterbody";
|
||||
const command = ["-m", "rf4_research.community_cli", source, "--url", args.url, "--state-file", args.stateFile, "--release-reservation", "--reserved-at", String(reservation.reserved_at)];
|
||||
const result = spawnSync(PYTHON, command, { cwd: ROOT, encoding: "utf8" });
|
||||
if (result.stdout) process.stdout.write(`${result.stdout.trim()}\n`);
|
||||
if (result.status !== 0 && result.stderr) process.stderr.write(result.stderr);
|
||||
}
|
||||
|
||||
function outputPath(args) {
|
||||
@@ -100,18 +111,24 @@ function outputPath(args) {
|
||||
|
||||
async function main() {
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
reserveCooldown(args);
|
||||
const executablePath = await resolveExecutable(args.executable);
|
||||
if (executablePath) console.log(`Using browser executable: ${executablePath}`);
|
||||
const reservation = reserveCooldown(args);
|
||||
const output = outputPath(args);
|
||||
const htmlOutput = path.resolve(args.htmlOutput || `${output}.html`);
|
||||
await fs.mkdir(path.dirname(htmlOutput), { recursive: true });
|
||||
await fs.mkdir(path.dirname(output), { recursive: true });
|
||||
|
||||
const executablePath = await resolveExecutable(args.executable);
|
||||
if (executablePath) console.log(`Using browser executable: ${executablePath}`);
|
||||
const context = await chromium.launchPersistentContext(path.resolve(args.profile), {
|
||||
headless: args.headless,
|
||||
...(executablePath ? { executablePath } : {}),
|
||||
});
|
||||
let context;
|
||||
try {
|
||||
context = await chromium.launchPersistentContext(path.resolve(args.profile), {
|
||||
headless: args.headless,
|
||||
...(executablePath ? { executablePath } : {}),
|
||||
});
|
||||
} catch (error) {
|
||||
releaseCooldown(args, reservation);
|
||||
throw error;
|
||||
}
|
||||
try {
|
||||
const page = context.pages()[0] || await context.newPage();
|
||||
await page.goto(args.url, { waitUntil: "domcontentloaded", timeout: 60_000 });
|
||||
|
||||
Reference in New Issue
Block a user