Add execute and await completion function#643
Conversation
tode-rl
left a comment
There was a problem hiding this comment.
small suggestions but looks good; is not supporting 3.8 breaking or doesn't matter bc it's just for our library?
| assert isinstance(received, str) | ||
|
|
||
|
|
||
| @pytest.mark.timeout(30) |
There was a problem hiding this comment.
Add a test that doesn't use pollingConfig to make sure basecase is ok?
There was a problem hiding this comment.
not necessary; the original test won't even use any of the polling config parameters
| def handle_timeout_error(error: Exception) -> DevboxAsyncExecutionDetailView: | ||
| if isinstance(error, APITimeoutError) or ( | ||
| isinstance(error, APIStatusError) and error.response.status_code == 408 | ||
| ): | ||
| return execution | ||
| raise error | ||
|
|
||
| def is_done(result: DevboxAsyncExecutionDetailView) -> bool: | ||
| return result.status == "completed" |
There was a problem hiding this comment.
These are re-used between the two functions, extract out?
There was a problem hiding this comment.
I thought about this, but poll_until requires a Callable with one argument. If I extract out, I would need two arguments, the error and the execution.
Then I'd have to define another helper function to do call that extracted function with the execution, which isn't good. I'd rather keep on_error generic with only one argument
| extra_query: Query | None = None, | ||
| extra_body: Body | None = None, | ||
| timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, | ||
| idempotency_key: str | None = None, |
There was a problem hiding this comment.
Is it worth instantiating idempotency_key -> command_id = str(uuid7()) within fn? idk if too much
There was a problem hiding this comment.
command_id is for internal use; idempotency_key should be specified by the user
It should be fine. Most if not all users are using python >= 3.9 |
New
execute_and_await_completiondoes execution and completion all in one.We now rely on
uuid-utilsto generateuuidv7for each command, making them idempotent. Since that library requires python version >= 3.9, I'm removing support for 3.8Also discovered the our polling mechanism doesn't handle timeouts well (thank you smoketests). Will fix in a follow-up