-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from seamapi/action-attempt-poll-fix
Fix action attempt poll logic
- Loading branch information
Showing
2 changed files
with
37 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import prompts from "prompts" | ||
import { getSeam } from "./get-seam" | ||
import { ActionAttemptsGetResponse } from "@seamapi/http/connect" | ||
|
||
export const interactForActionAttemptPoll = async ( | ||
action_attempt: ActionAttemptsGetResponse["action_attempt"] | ||
) => { | ||
if (action_attempt.status === "pending") { | ||
const { poll_for_action_attempt } = await prompts({ | ||
name: "poll_for_action_attempt", | ||
message: "Would you like to poll the action attempt until it's ready?", | ||
type: "toggle", | ||
initial: true, | ||
active: "yes", | ||
inactive: "no", | ||
}) | ||
|
||
if (poll_for_action_attempt) { | ||
const seam = await getSeam() | ||
const { action_attempt_id } = action_attempt | ||
|
||
const updated_action_attempt = await seam.actionAttempts.get( | ||
{ action_attempt_id }, | ||
{ waitForActionAttempt: { pollingInterval: 240, timeout: 10_000 } } | ||
) | ||
|
||
console.dir(updated_action_attempt, { depth: null }) | ||
} | ||
} | ||
} |