Skip to content

Commit b115c4b

Browse files
committed
extract wait_for_action() method
1 parent c5e1dbd commit b115c4b

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/binarylane/console/runners/action.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import shutil
55
import sys
66
import time
7-
from typing import TYPE_CHECKING, Any
7+
from typing import TYPE_CHECKING, Any, Tuple
88

99
from binarylane.console.runners.command import CommandRunner
1010

@@ -51,17 +51,14 @@ def _progress(self, progress: str) -> None:
5151
blanks = " " * (shutil.get_terminal_size().columns - 1)
5252
print(f"\r{blanks}\r{progress}", end="", file=sys.stderr)
5353

54-
def response(self, status_code: int, received: Any) -> None:
55-
# If async is requested, use standard handler
56-
if self._async:
57-
super().response(status_code, received)
58-
return
54+
def wait_for_action(self, status_code: int, received: Any) -> Tuple[int, Any]:
55+
"""While received is an ActionResponse, show progress and wait for the action to complete"""
5956

6057
from binarylane.api.actions.get_v2_actions_action_id import sync_detailed
6158
from binarylane.models.action_response import ActionResponse
6259

6360
# FIXME: Extract _get_action(id: int) -> Tuple[int, Any] method so that derived class can call that instead
64-
# Derived class may provide an Action ID directly:
61+
# Caller may provide an Action ID directly:
6562
if isinstance(received, int):
6663
response = sync_detailed(received, client=self._client)
6764
status_code, received = response.status_code, response.parsed
@@ -82,5 +79,16 @@ def response(self, status_code: int, received: Any) -> None:
8279
response = sync_detailed(received.action.id, client=self._client)
8380
status_code, received = response.status_code, response.parsed
8481

82+
return status_code, received
83+
84+
85+
def response(self, status_code: int, received: Any) -> None:
86+
# If async is requested, use standard handler
87+
if self._async:
88+
super().response(status_code, received)
89+
return
90+
91+
status_code, received = self.wait_for_action(status_code, received)
92+
8593
# Action has now completed (or errored), process final response
8694
super().response(status_code, received)

src/binarylane/console/runners/actionlink.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def response(self, status_code: int, received: Any) -> None:
1919
# Show action progress on stdout
2020
if not self._async:
2121
action_id = links.actions[0].id
22-
super().response(status_code, action_id)
22+
self.wait_for_action(status_code, action_id)
2323

2424
# Print the 'other' object (e.g. server) from the response
2525
self._printer.print(received)

0 commit comments

Comments
 (0)