Skip to content

Commit

Permalink
Use is_terminal rather than waiting on states.
Browse files Browse the repository at this point in the history
  • Loading branch information
cleve-fauna committed Jan 27, 2025
1 parent 6c009f8 commit 8c1999d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/commands/export/create.mjs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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: {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/export/get.mjs
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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: {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/export/wait.mjs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions src/lib/account-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
17 changes: 7 additions & 10 deletions test/commands/export/wait.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -40,17 +40,14 @@ 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.",
);
});

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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8c1999d

Please sign in to comment.