Skip to content

Commit 2c77770

Browse files
IWF-166: Regenerating api client from idl and fixing tests (#36)
* IWF-166: Regenerating api client from idl and fixing tests * IWF-166: Fixing lint warning
1 parent 6b47baf commit 2c77770

22 files changed

+460
-69
lines changed

iwf/command_request.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import time
21
from dataclasses import dataclass
32
from datetime import timedelta
43
from typing import Optional, Union
@@ -17,15 +16,15 @@
1716
@dataclass
1817
class TimerCommand:
1918
command_id: str
20-
firing_unix_timestamp_seconds: int
19+
duration_seconds: int
2120

2221
@classmethod
2322
def timer_command_by_duration(
2423
cls, duration: timedelta, command_id: Optional[str] = None
2524
):
2625
return TimerCommand(
2726
command_id if command_id is not None else "",
28-
int(time.time()) + int(duration.total_seconds()),
27+
int(duration.total_seconds()),
2928
)
3029

3130

@@ -82,19 +81,19 @@ def _to_idl_command_request(request: CommandRequest) -> IdlCommandRequest:
8281
)
8382

8483
timer_commands = [
85-
IdlTimerCommand(t.command_id, t.firing_unix_timestamp_seconds)
84+
IdlTimerCommand(t.duration_seconds, t.command_id)
8685
for t in request.commands
8786
if isinstance(t, TimerCommand)
8887
]
8988

9089
internal_channel_commands = [
91-
IdlInternalChannelCommand(i.command_id, i.channel_name)
90+
IdlInternalChannelCommand(i.channel_name, i.command_id)
9291
for i in request.commands
9392
if isinstance(i, InternalChannelCommand)
9493
]
9594

9695
signal_commands = [
97-
IdlSignalCommand(i.command_id, i.channel_name)
96+
IdlSignalCommand(i.channel_name, i.command_id)
9897
for i in request.commands
9998
if isinstance(i, SignalChannelCommand)
10099
]

iwf/iwf_api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" A client library for accessing Workflow APIs """
2+
23
from .client import AuthenticatedClient, Client
34

45
__all__ = (
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
from http import HTTPStatus
2+
from typing import Any, Dict, Optional, Union, cast
3+
4+
import httpx
5+
6+
from ... import errors
7+
from ...client import Client
8+
from ...models.error_response import ErrorResponse
9+
from ...models.trigger_continue_as_new_request import TriggerContinueAsNewRequest
10+
from ...types import Response
11+
12+
13+
def _get_kwargs(
14+
*,
15+
client: Client,
16+
json_body: TriggerContinueAsNewRequest,
17+
) -> Dict[str, Any]:
18+
url = "{}/api/v1/workflow/triggerContinueAsNew".format(client.base_url)
19+
20+
headers: Dict[str, str] = client.get_headers()
21+
cookies: Dict[str, Any] = client.get_cookies()
22+
23+
json_json_body = json_body.to_dict()
24+
25+
return {
26+
"method": "post",
27+
"url": url,
28+
"headers": headers,
29+
"cookies": cookies,
30+
"timeout": client.get_timeout(),
31+
"follow_redirects": client.follow_redirects,
32+
"json": json_json_body,
33+
}
34+
35+
36+
def _parse_response(
37+
*, client: Client, response: httpx.Response
38+
) -> Optional[Union[Any, ErrorResponse]]:
39+
if response.status_code == HTTPStatus.OK:
40+
response_200 = cast(Any, None)
41+
return response_200
42+
if response.status_code == HTTPStatus.BAD_REQUEST:
43+
response_400 = ErrorResponse.from_dict(response.json())
44+
45+
return response_400
46+
if client.raise_on_unexpected_status:
47+
raise errors.UnexpectedStatus(response.status_code, response.content)
48+
else:
49+
return None
50+
51+
52+
def _build_response(
53+
*, client: Client, response: httpx.Response
54+
) -> Response[Union[Any, ErrorResponse]]:
55+
return Response(
56+
status_code=HTTPStatus(response.status_code),
57+
content=response.content,
58+
headers=response.headers,
59+
parsed=_parse_response(client=client, response=response),
60+
)
61+
62+
63+
def sync_detailed(
64+
*,
65+
client: Client,
66+
json_body: TriggerContinueAsNewRequest,
67+
) -> Response[Union[Any, ErrorResponse]]:
68+
"""trigger ContinueAsNew for a workflow
69+
70+
Args:
71+
json_body (TriggerContinueAsNewRequest):
72+
73+
Raises:
74+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
75+
httpx.TimeoutException: If the request takes longer than Client.timeout.
76+
77+
Returns:
78+
Response[Union[Any, ErrorResponse]]
79+
"""
80+
81+
kwargs = _get_kwargs(
82+
client=client,
83+
json_body=json_body,
84+
)
85+
86+
response = httpx.request(
87+
verify=client.verify_ssl,
88+
**kwargs,
89+
)
90+
91+
return _build_response(client=client, response=response)
92+
93+
94+
def sync(
95+
*,
96+
client: Client,
97+
json_body: TriggerContinueAsNewRequest,
98+
) -> Optional[Union[Any, ErrorResponse]]:
99+
"""trigger ContinueAsNew for a workflow
100+
101+
Args:
102+
json_body (TriggerContinueAsNewRequest):
103+
104+
Raises:
105+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
106+
httpx.TimeoutException: If the request takes longer than Client.timeout.
107+
108+
Returns:
109+
Union[Any, ErrorResponse]
110+
"""
111+
112+
return sync_detailed(
113+
client=client,
114+
json_body=json_body,
115+
).parsed
116+
117+
118+
async def asyncio_detailed(
119+
*,
120+
client: Client,
121+
json_body: TriggerContinueAsNewRequest,
122+
) -> Response[Union[Any, ErrorResponse]]:
123+
"""trigger ContinueAsNew for a workflow
124+
125+
Args:
126+
json_body (TriggerContinueAsNewRequest):
127+
128+
Raises:
129+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
130+
httpx.TimeoutException: If the request takes longer than Client.timeout.
131+
132+
Returns:
133+
Response[Union[Any, ErrorResponse]]
134+
"""
135+
136+
kwargs = _get_kwargs(
137+
client=client,
138+
json_body=json_body,
139+
)
140+
141+
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
142+
response = await _client.request(**kwargs)
143+
144+
return _build_response(client=client, response=response)
145+
146+
147+
async def asyncio(
148+
*,
149+
client: Client,
150+
json_body: TriggerContinueAsNewRequest,
151+
) -> Optional[Union[Any, ErrorResponse]]:
152+
"""trigger ContinueAsNew for a workflow
153+
154+
Args:
155+
json_body (TriggerContinueAsNewRequest):
156+
157+
Raises:
158+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
159+
httpx.TimeoutException: If the request takes longer than Client.timeout.
160+
161+
Returns:
162+
Union[Any, ErrorResponse]
163+
"""
164+
165+
return (
166+
await asyncio_detailed(
167+
client=client,
168+
json_body=json_body,
169+
)
170+
).parsed

iwf/iwf_api/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .timer_command import TimerCommand
3131
from .timer_result import TimerResult
3232
from .timer_status import TimerStatus
33+
from .trigger_continue_as_new_request import TriggerContinueAsNewRequest
3334
from .wait_until_api_failure_policy import WaitUntilApiFailurePolicy
3435
from .worker_error_response import WorkerErrorResponse
3536
from .workflow_conditional_close import WorkflowConditionalClose
@@ -107,6 +108,7 @@
107108
"TimerCommand",
108109
"TimerResult",
109110
"TimerStatus",
111+
"TriggerContinueAsNewRequest",
110112
"WaitUntilApiFailurePolicy",
111113
"WorkerErrorResponse",
112114
"WorkflowConditionalClose",

iwf/iwf_api/models/inter_state_channel_command.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,66 @@
1-
from typing import Any, Dict, List, Type, TypeVar
1+
from typing import Any, Dict, List, Type, TypeVar, Union
22

33
import attr
44

5+
from ..types import UNSET, Unset
6+
57
T = TypeVar("T", bound="InterStateChannelCommand")
68

79

810
@attr.s(auto_attribs=True)
911
class InterStateChannelCommand:
1012
"""
1113
Attributes:
12-
command_id (str):
1314
channel_name (str):
15+
command_id (Union[Unset, str]):
16+
at_least (Union[Unset, int]):
17+
at_most (Union[Unset, int]):
1418
"""
1519

16-
command_id: str
1720
channel_name: str
21+
command_id: Union[Unset, str] = UNSET
22+
at_least: Union[Unset, int] = UNSET
23+
at_most: Union[Unset, int] = UNSET
1824
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
1925

2026
def to_dict(self) -> Dict[str, Any]:
21-
command_id = self.command_id
2227
channel_name = self.channel_name
28+
command_id = self.command_id
29+
at_least = self.at_least
30+
at_most = self.at_most
2331

2432
field_dict: Dict[str, Any] = {}
2533
field_dict.update(self.additional_properties)
2634
field_dict.update(
2735
{
28-
"commandId": command_id,
2936
"channelName": channel_name,
3037
}
3138
)
39+
if command_id is not UNSET:
40+
field_dict["commandId"] = command_id
41+
if at_least is not UNSET:
42+
field_dict["atLeast"] = at_least
43+
if at_most is not UNSET:
44+
field_dict["atMost"] = at_most
3245

3346
return field_dict
3447

3548
@classmethod
3649
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
3750
d = src_dict.copy()
38-
command_id = d.pop("commandId")
39-
4051
channel_name = d.pop("channelName")
4152

53+
command_id = d.pop("commandId", UNSET)
54+
55+
at_least = d.pop("atLeast", UNSET)
56+
57+
at_most = d.pop("atMost", UNSET)
58+
4259
inter_state_channel_command = cls(
43-
command_id=command_id,
4460
channel_name=channel_name,
61+
command_id=command_id,
62+
at_least=at_least,
63+
at_most=at_most,
4564
)
4665

4766
inter_state_channel_command.additional_properties = d

iwf/iwf_api/models/persistence_loading_policy.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ class PersistenceLoadingPolicy:
1515
persistence_loading_type (Union[Unset, PersistenceLoadingType]):
1616
partial_loading_keys (Union[Unset, List[str]]):
1717
locking_keys (Union[Unset, List[str]]):
18+
use_key_as_prefix (Union[Unset, bool]):
1819
"""
1920

2021
persistence_loading_type: Union[Unset, PersistenceLoadingType] = UNSET
2122
partial_loading_keys: Union[Unset, List[str]] = UNSET
2223
locking_keys: Union[Unset, List[str]] = UNSET
24+
use_key_as_prefix: Union[Unset, bool] = UNSET
2325
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
2426

2527
def to_dict(self) -> Dict[str, Any]:
@@ -35,6 +37,8 @@ def to_dict(self) -> Dict[str, Any]:
3537
if not isinstance(self.locking_keys, Unset):
3638
locking_keys = self.locking_keys
3739

40+
use_key_as_prefix = self.use_key_as_prefix
41+
3842
field_dict: Dict[str, Any] = {}
3943
field_dict.update(self.additional_properties)
4044
field_dict.update({})
@@ -44,6 +48,8 @@ def to_dict(self) -> Dict[str, Any]:
4448
field_dict["partialLoadingKeys"] = partial_loading_keys
4549
if locking_keys is not UNSET:
4650
field_dict["lockingKeys"] = locking_keys
51+
if use_key_as_prefix is not UNSET:
52+
field_dict["useKeyAsPrefix"] = use_key_as_prefix
4753

4854
return field_dict
4955

@@ -61,10 +67,13 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
6167

6268
locking_keys = cast(List[str], d.pop("lockingKeys", UNSET))
6369

70+
use_key_as_prefix = d.pop("useKeyAsPrefix", UNSET)
71+
6472
persistence_loading_policy = cls(
6573
persistence_loading_type=persistence_loading_type,
6674
partial_loading_keys=partial_loading_keys,
6775
locking_keys=locking_keys,
76+
use_key_as_prefix=use_key_as_prefix,
6877
)
6978

7079
persistence_loading_policy.additional_properties = d

iwf/iwf_api/models/persistence_loading_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
class PersistenceLoadingType(str, Enum):
55
LOAD_ALL_WITHOUT_LOCKING = "LOAD_ALL_WITHOUT_LOCKING"
6+
LOAD_ALL_WITH_PARTIAL_LOCK = "LOAD_ALL_WITH_PARTIAL_LOCK"
67
LOAD_NONE = "LOAD_NONE"
78
LOAD_PARTIAL_WITHOUT_LOCKING = "LOAD_PARTIAL_WITHOUT_LOCKING"
89
LOAD_PARTIAL_WITH_EXCLUSIVE_LOCK = "LOAD_PARTIAL_WITH_EXCLUSIVE_LOCK"

iwf/iwf_api/models/retry_policy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def to_dict(self) -> Dict[str, Any]:
4444
if maximum_attempts is not UNSET:
4545
field_dict["maximumAttempts"] = maximum_attempts
4646
if maximum_attempts_duration_seconds is not UNSET:
47-
field_dict[
48-
"maximumAttemptsDurationSeconds"
49-
] = maximum_attempts_duration_seconds
47+
field_dict["maximumAttemptsDurationSeconds"] = (
48+
maximum_attempts_duration_seconds
49+
)
5050

5151
return field_dict
5252

0 commit comments

Comments
 (0)