Skip to content

Commit

Permalink
Remove running state
Browse files Browse the repository at this point in the history
Signed-off-by: gearnode <bryan@frimin.fr>
  • Loading branch information
gearnode committed Jul 14, 2023
1 parent d37529b commit 817bfb9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export interface FetchExecutionRequest {
}

export type ExecutionState =
| "running"
| "created"
| "failed"
| "succeed"
Expand Down
5 changes: 2 additions & 3 deletions src/getExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ export async function getExecution(
if (response)
return Promise.resolve({
...response,
// TODO: bump a major and drop `running` state (invalid API state)
state: response.state === "started" ? "running" : response.state,
state: response.state,
});

throw new APIError("execution not found", "");
throw new APIError("execution not found", "not found");
}
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export const defer: Defer = (fn, options) => {
console.log(`[defer.run][${fn.name}] defer ignore, no token found.`);

const id = randomUUID();
__database.set(id, { id: id, state: "running" });
__database.set(id, { id: id, state: "started" });
execLocally(id, fn, functionArguments);
return { id };
};
Expand Down Expand Up @@ -335,7 +335,7 @@ export const delay: DeferDelay = (deferFn, delay) => {
console.log(`[defer.run][${fn.name}] defer ignore, no token found.`);

const id = randomUUID();
__database.set(id, { id: id, state: "running" });
__database.set(id, { id: id, state: "started" });
execLocally(id, fn, functionArguments);
return { id };
};
Expand Down Expand Up @@ -404,7 +404,7 @@ export const addMetadata: DeferAddMetadata = (deferFn, metadata) => {
console.log(`[defer.run][${fn.name}] defer ignore, no token found.`);

const id = randomUUID();
__database.set(id, { id: id, state: "running" });
__database.set(id, { id: id, state: "started" });
execLocally(id, fn, functionArguments);
return { id };
};
Expand Down Expand Up @@ -456,7 +456,7 @@ export const awaitResult: DeferAwaitResult =
response = await waitExecutionResult(__httpClient, { id: id });
} else {
const id = randomUUID();
__database.set(id, { id: id, state: "running" });
__database.set(id, { id: id, state: "started" });
response = await execLocally(id, fn, functionArguments);
}

Expand Down
2 changes: 1 addition & 1 deletion src/next/useDeferRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const useDeferRoute = <
return [
execute,
{
loading: !!status && ["started", "created", "running"].includes(status),
loading: !!status && ["started", "created"].includes(status),
result,
error,
},
Expand Down
2 changes: 1 addition & 1 deletion tests/awaitResult.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("awaitResult(deferFn)", () => {
})
// second `/runs/:id` call
.mockImplementationOnce(() => {
return { id: "1", state: "running" };
return { id: "1", state: "started" };
})
// third `/runs/:id` call
.mockImplementationOnce(() => {
Expand Down

0 comments on commit 817bfb9

Please sign in to comment.