Skip to content

Commit 40da3a4

Browse files
Merge pull request #92 from seamapi/action-attempt-poll-fix
Fix action attempt poll logic
2 parents d6f00eb + 7942a2d commit 40da3a4

2 files changed

Lines changed: 37 additions & 17 deletions

File tree

cli.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ContextHelpers } from "./lib/types"
1818
import { version } from "./package.json"
1919
import { interactForUseRemoteApiDefs } from "./lib/interact-for-use-remote-api-defs"
2020
import { randomBytes } from "node:crypto"
21+
import { interactForActionAttemptPoll } from "./lib/interact-for-action-attempt-poll"
2122

2223
const sections = [
2324
{
@@ -245,23 +246,12 @@ async function cli(args: ParsedArgs) {
245246
}
246247
}
247248

248-
if ("action_attempt" in response.data) {
249-
const { poll_for_action_attempt } = await prompts({
250-
name: "poll_for_action_attempt",
251-
message: "Would you like to poll the action attempt until it's ready?",
252-
type: "toggle",
253-
initial: true,
254-
active: "yes",
255-
inactive: "no",
256-
})
257-
258-
if (poll_for_action_attempt) {
259-
const { action_attempt_id } = response.data.action_attempt
260-
await seam.actionAttempts.get(
261-
{ action_attempt_id },
262-
{ waitForActionAttempt: { pollingInterval: 240, timeout: 10_000 } }
263-
)
264-
}
249+
if (
250+
response.data &&
251+
typeof response.data === "object" &&
252+
"action_attempt" in response.data
253+
) {
254+
interactForActionAttemptPoll(response.data.action_attempt)
265255
}
266256
}
267257

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import prompts from "prompts"
2+
import { getSeam } from "./get-seam"
3+
import { ActionAttemptsGetResponse } from "@seamapi/http/connect"
4+
5+
export const interactForActionAttemptPoll = async (
6+
action_attempt: ActionAttemptsGetResponse["action_attempt"]
7+
) => {
8+
if (action_attempt.status === "pending") {
9+
const { poll_for_action_attempt } = await prompts({
10+
name: "poll_for_action_attempt",
11+
message: "Would you like to poll the action attempt until it's ready?",
12+
type: "toggle",
13+
initial: true,
14+
active: "yes",
15+
inactive: "no",
16+
})
17+
18+
if (poll_for_action_attempt) {
19+
const seam = await getSeam()
20+
const { action_attempt_id } = action_attempt
21+
22+
const updated_action_attempt = await seam.actionAttempts.get(
23+
{ action_attempt_id },
24+
{ waitForActionAttempt: { pollingInterval: 240, timeout: 10_000 } }
25+
)
26+
27+
console.dir(updated_action_attempt, { depth: null })
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)