Skip to content

Commit 8c54178

Browse files
razor-xseambot
andauthored
feat: Default wait_for_action_attempt to True (#91)
* feat: Default wait_for_action_attempt to True * Update reset_sandbox test * ci: Format code --------- Co-authored-by: Seam Bot <devops@getseam.com>
1 parent 84fbaad commit 8c54178

7 files changed

Lines changed: 48 additions & 36 deletions

File tree

README.rst

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Personal Access Token
9999

100100
A Personal Access Token is scoped to a Seam Console user.
101101
Obtain one from the Seam Console.
102-
A workspace id must be provided when using this method and all requests will be scoped to that workspace.
102+
A workspace ID must be provided when using this method and all requests will be scoped to that workspace.
103103

104104
.. code-block:: python
105105
@@ -118,50 +118,60 @@ A workspace id must be provided when using this method and all requests will be
118118
Action Attempts
119119
~~~~~~~~~~~~~~~
120120

121-
Some asynchronous operations, e.g., unlocking a door, return an `action attempt <https://docs.seam.co/latest/core-concepts/action-attempts>`_.
122-
Seam tracks the progress of requested operation and updates the action attempt.
121+
Some asynchronous operations, e.g., unlocking a door, return an
122+
`action attempt <https://docs.seam.co/latest/core-concepts/action-attempts>`_.
123+
Seam tracks the progress of the requested operation and updates the action attempt
124+
when it succeeds or fails.
123125

124126
To make working with action attempts more convenient for applications,
125-
this library provides the ``wait_for_action_attempt`` option.
127+
this library provides the ``wait_for_action_attempt`` option and enables it by default.
126128

127-
Pass the option per-request,
129+
When the ``wait_for_action_attempt`` option is enable, the SDK:
130+
131+
- Polls the action attempt up to the ``timeout``
132+
at the ``polling_interval`` (both in seconds).
133+
- Resolves with a fresh copy of the successful action attempt.
134+
- Raises a ``SeamActionAttemptFailedError`` if the action attempt is unsuccessful.
135+
- Raises a ``SeamActionAttemptTimeoutError`` if the action attempt is still pending when the ``timeout`` is reached.
136+
- Both errors expose an ``action_attempt`` property.
137+
138+
If you already have an action attempt ID
139+
and want to wait for it to resolve, simply use
128140

129141
.. code-block:: python
130142
131-
seam.locks.unlock_door(
132-
device_id=device_id,
133-
wait_for_action_attempt=True,
143+
seam.action_attempts.get(action_attempt_id=action_attempt_id)
144+
145+
Or, to get the current state of an action attempt by ID without waiting,
146+
147+
.. code-block:: python
148+
149+
seam.action_attempts.get(
150+
action_attempt_id=action_attempt_id,
151+
wait_for_action_attempt=False,
134152
)
135153
136-
or set the default option for the client:
154+
To disable this behavior, set the default option for the client,
137155

138156
.. code-block:: python
139157
140158
seam = Seam(
141159
api_key="your-api-key",
142-
wait_for_action_attempt=True,
160+
wait_for_action_attempt=False,
143161
)
144162
145163
seam.locks.unlock_door(device_id=device_id)
146164
147-
If you already have an action attempt id
148-
and want to wait for it to resolve, simply use
165+
or the behavior may be configured per-request,
149166

150167
.. code-block:: python
151168
152-
seam.action_attempts.get(
153-
action_attempt_id=action_attempt_id,
154-
wait_for_action_attempt=True,
169+
seam.locks.unlock_door(
170+
device_id=device_id,
171+
wait_for_action_attempt=False,
155172
)
156173
157-
Using the ``wait_for_action_attempt`` option:
158-
159-
- Polls the action attempt up to the ``timeout``
160-
at the ``polling_interval`` (both in seconds).
161-
- Resolves with a fresh copy of the successful action attempt.
162-
- Raises a ``SeamActionAttemptFailedError`` if the action attempt is unsuccessful.
163-
- Raises a ``SeamActionAttemptTimeoutError`` if the action attempt is still pending when the ``timeout`` is reached.
164-
- Both errors expose an ``action_attempt`` property.
174+
The ``polling_interval`` and ``timeout`` may be configured for the client or per-request, for example
165175

166176
.. code-block:: python
167177

seam/models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(
3232
personal_access_token: Optional[str] = None,
3333
workspace_id: Optional[str] = None,
3434
endpoint: Optional[str] = None,
35-
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = False,
35+
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = True,
3636
):
3737
raise NotImplementedError
3838

@@ -43,7 +43,7 @@ def from_api_key(
4343
api_key: str,
4444
*,
4545
endpoint: Optional[str] = None,
46-
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = False,
46+
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = True,
4747
) -> Self:
4848
raise NotImplementedError
4949

@@ -55,7 +55,7 @@ def from_personal_access_token(
5555
workspace_id: str,
5656
*,
5757
endpoint: Optional[str] = None,
58-
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = False,
58+
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = True,
5959
) -> Self:
6060
raise NotImplementedError
6161

@@ -90,7 +90,7 @@ def __init__(
9090
personal_access_token: str,
9191
*,
9292
endpoint: Optional[str] = None,
93-
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = False,
93+
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = True,
9494
):
9595
raise NotImplementedError
9696

@@ -101,6 +101,6 @@ def from_personal_access_token(
101101
personal_access_token: str,
102102
*,
103103
endpoint: Optional[str] = None,
104-
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = False,
104+
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = True,
105105
) -> Self:
106106
raise NotImplementedError

seam/modules/action_attempts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def resolve_action_attempt(
4747
client: SeamHttpClient,
4848
*,
4949
action_attempt: ActionAttempt,
50-
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None
50+
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]]
5151
) -> ActionAttempt:
5252
if wait_for_action_attempt is True:
5353
return poll_until_ready(

seam/seam.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(
2424
personal_access_token: Optional[str] = None,
2525
workspace_id: Optional[str] = None,
2626
endpoint: Optional[str] = None,
27-
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = False,
27+
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = True,
2828
):
2929
"""
3030
Parameters
@@ -61,7 +61,7 @@ def from_api_key(
6161
api_key: str,
6262
*,
6363
endpoint: Optional[str] = None,
64-
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = False,
64+
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = True,
6565
) -> Self:
6666
return cls(
6767
api_key, endpoint=endpoint, wait_for_action_attempt=wait_for_action_attempt
@@ -74,7 +74,7 @@ def from_personal_access_token(
7474
workspace_id: str,
7575
*,
7676
endpoint: Optional[str] = None,
77-
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = False,
77+
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = True,
7878
) -> Self:
7979
return cls(
8080
personal_access_token=personal_access_token,

seam/seam_multi_workspace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(
3535
personal_access_token: str,
3636
*,
3737
endpoint: Optional[str] = None,
38-
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = False,
38+
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = True,
3939
):
4040
"""
4141
Parameters
@@ -76,7 +76,7 @@ def from_personal_access_token(
7676
personal_access_token: str,
7777
*,
7878
endpoint: Optional[str] = None,
79-
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = False,
79+
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = True,
8080
) -> Self:
8181
return cls(
8282
personal_access_token=personal_access_token,

test/test_init_seam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
def test_init_seam_with_fixture(seam: Seam):
55
assert seam.lts_version
6-
assert seam.wait_for_action_attempt is False
6+
assert seam.wait_for_action_attempt is True

test/workspaces/test_workspaces.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ def test_workspaces(seam: Seam):
88
ws_list = seam.workspaces.list()
99
assert len(ws_list) > 0
1010

11-
reset_sandbox_action_attempt = seam.workspaces.reset_sandbox()
11+
reset_sandbox_action_attempt = seam.workspaces.reset_sandbox(
12+
wait_for_action_attempt=False
13+
)
1214
assert reset_sandbox_action_attempt.action_type == "RESET_SANDBOX_WORKSPACE"

0 commit comments

Comments
 (0)