From 8c1999d68edf26e512d07f5dec3835bf8f97c168 Mon Sep 17 00:00:00 2001 From: Cleve Stuart Date: Mon, 27 Jan 2025 08:47:11 -0500 Subject: [PATCH] Use is_terminal rather than waiting on states. --- src/commands/export/create.mjs | 3 +-- src/commands/export/get.mjs | 3 +-- src/commands/export/wait.mjs | 3 +-- src/lib/account-api.mjs | 4 ---- test/commands/export/wait.mjs | 17 +++++++---------- 5 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/commands/export/create.mjs b/src/commands/export/create.mjs index 46ce93c3..216d0495 100644 --- a/src/commands/export/create.mjs +++ b/src/commands/export/create.mjs @@ -1,7 +1,6 @@ // @ts-check import { container } from "../../config/container.mjs"; -import { EXPORT_TERMINAL_STATES } from "../../lib/account-api.mjs"; import { ValidationError } from "../../lib/errors.mjs"; import { colorize, Format } from "../../lib/formatting/colorize.mjs"; import { DATABASE_PATH_OPTIONS } from "../../lib/options.mjs"; @@ -40,7 +39,7 @@ async function createS3Export(argv) { format, }); - if (wait && !EXPORT_TERMINAL_STATES.includes(createdExport.state)) { + if (wait && !createdExport.is_terminal) { createdExport = await waitUntilExportIsReady({ id: createdExport.id, opts: { diff --git a/src/commands/export/get.mjs b/src/commands/export/get.mjs index 43e00fbe..ea1f29aa 100644 --- a/src/commands/export/get.mjs +++ b/src/commands/export/get.mjs @@ -1,5 +1,4 @@ import { container } from "../../config/container.mjs"; -import { EXPORT_TERMINAL_STATES } from "../../lib/account-api.mjs"; import { colorize, Format } from "../../lib/formatting/colorize.mjs"; import { WAIT_OPTIONS, waitUntilExportIsReady } from "./wait.mjs"; @@ -9,7 +8,7 @@ async function getExport(argv) { const { exportId, json, color, wait, maxWait, quiet } = argv; let response = await getExport({ exportId }); - if (wait && !EXPORT_TERMINAL_STATES.includes(response.state)) { + if (wait && !response.is_terminal) { response = await waitUntilExportIsReady({ id: exportId, opts: { diff --git a/src/commands/export/wait.mjs b/src/commands/export/wait.mjs index 1125ffe6..b155115d 100644 --- a/src/commands/export/wait.mjs +++ b/src/commands/export/wait.mjs @@ -1,7 +1,6 @@ // @ts-check import { container } from "../../config/container.mjs"; -import { EXPORT_TERMINAL_STATES } from "../../lib/account-api.mjs"; import { CommandError } from "../../lib/errors.mjs"; import { colorize, Format } from "../../lib/formatting/colorize.mjs"; import { isTTY } from "../../lib/utils.mjs"; @@ -169,7 +168,7 @@ export async function waitAndCheckExportState({ const data = await getExport({ exportId: id }); // If the export is ready, return the data - if (EXPORT_TERMINAL_STATES.includes(data.state)) { + if (data.is_terminal) { statusHandler( colorize(`${id} has a terminal state of ${data.state}.`, { format: Format.LOG, diff --git a/src/lib/account-api.mjs b/src/lib/account-api.mjs index d13c97b4..20ccc835 100644 --- a/src/lib/account-api.mjs +++ b/src/lib/account-api.mjs @@ -22,10 +22,6 @@ export const ExportState = { }; export const EXPORT_STATES = Object.values(ExportState); -export const EXPORT_TERMINAL_STATES = [ - ExportState.Complete, - ExportState.Failed, -]; let accountUrl = process.env.FAUNA_ACCOUNT_URL ?? "https://account.fauna.com"; diff --git a/test/commands/export/wait.mjs b/test/commands/export/wait.mjs index 4dbd0663..252c502b 100644 --- a/test/commands/export/wait.mjs +++ b/test/commands/export/wait.mjs @@ -24,7 +24,7 @@ describe("export wait helpers", () => { describe("waitUntilExportIsReady", () => { it("should return export data when export completes successfully", async () => { const exportId = "test-export-id"; - const exportData = { id: exportId, state: ExportState.Complete }; + const exportData = { id: exportId, is_terminal: true, state: ExportState.Complete }; const statusHandler = sinon.stub(); getExport.resolves(exportData); @@ -40,9 +40,6 @@ describe("export wait helpers", () => { expect(statusHandler).to.have.been.calledWith( `test-export-id is Pending and not yet started.`, ); - expect(statusHandler).to.have.been.calledWith( - "test-export-id is Pending and not yet started.", - ); expect(statusHandler).to.have.been.calledWith( "test-export-id has a terminal state of Complete.", ); @@ -50,7 +47,7 @@ describe("export wait helpers", () => { it("should not print status when quiet is true", async () => { const exportId = "test-export-id"; - const exportData = { id: exportId, state: ExportState.Complete }; + const exportData = { id: exportId, is_terminal: true }; const statusHandler = sinon.stub(); getExport.resolves(exportData); @@ -92,9 +89,9 @@ describe("export wait helpers", () => { getExport .onFirstCall() - .resolves({ id: exportId, state: ExportState.Pending }) + .resolves({ id: exportId, is_terminal: false, state: ExportState.Pending }) .onSecondCall() - .resolves({ id: exportId, state: ExportState.Complete }); + .resolves({ id: exportId, is_terminal: true, state: ExportState.Complete }); const result = await waitAndCheckExportState({ id: exportId, @@ -134,11 +131,11 @@ describe("export wait helpers", () => { getExport .onFirstCall() - .resolves({ id: exportId, state: ExportState.Pending }) + .resolves({ id: exportId, is_terminal: false }) .onSecondCall() - .resolves({ id: exportId, state: ExportState.Pending }) + .resolves({ id: exportId, is_terminal: false }) .onThirdCall() - .resolves({ id: exportId, state: ExportState.Complete }); + .resolves({ id: exportId, is_terminal: true }); await waitAndCheckExportState({ id: exportId,