Skip to content

Commit

Permalink
IWF-166: Regenerating api client from idl and fixing tests (#36)
Browse files Browse the repository at this point in the history
* IWF-166: Regenerating api client from idl and fixing tests

* IWF-166: Fixing lint warning
  • Loading branch information
stevo89519 authored Oct 3, 2024
1 parent 6b47baf commit 2c77770
Show file tree
Hide file tree
Showing 22 changed files with 460 additions and 69 deletions.
11 changes: 5 additions & 6 deletions iwf/command_request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import time
from dataclasses import dataclass
from datetime import timedelta
from typing import Optional, Union
Expand All @@ -17,15 +16,15 @@
@dataclass
class TimerCommand:
command_id: str
firing_unix_timestamp_seconds: int
duration_seconds: int

@classmethod
def timer_command_by_duration(
cls, duration: timedelta, command_id: Optional[str] = None
):
return TimerCommand(
command_id if command_id is not None else "",
int(time.time()) + int(duration.total_seconds()),
int(duration.total_seconds()),
)


Expand Down Expand Up @@ -82,19 +81,19 @@ def _to_idl_command_request(request: CommandRequest) -> IdlCommandRequest:
)

timer_commands = [
IdlTimerCommand(t.command_id, t.firing_unix_timestamp_seconds)
IdlTimerCommand(t.duration_seconds, t.command_id)
for t in request.commands
if isinstance(t, TimerCommand)
]

internal_channel_commands = [
IdlInternalChannelCommand(i.command_id, i.channel_name)
IdlInternalChannelCommand(i.channel_name, i.command_id)
for i in request.commands
if isinstance(i, InternalChannelCommand)
]

signal_commands = [
IdlSignalCommand(i.command_id, i.channel_name)
IdlSignalCommand(i.channel_name, i.command_id)
for i in request.commands
if isinstance(i, SignalChannelCommand)
]
Expand Down
1 change: 1 addition & 0 deletions iwf/iwf_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" A client library for accessing Workflow APIs """

from .client import AuthenticatedClient, Client

__all__ = (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
from http import HTTPStatus
from typing import Any, Dict, Optional, Union, cast

import httpx

from ... import errors
from ...client import Client
from ...models.error_response import ErrorResponse
from ...models.trigger_continue_as_new_request import TriggerContinueAsNewRequest
from ...types import Response


def _get_kwargs(
*,
client: Client,
json_body: TriggerContinueAsNewRequest,
) -> Dict[str, Any]:
url = "{}/api/v1/workflow/triggerContinueAsNew".format(client.base_url)

headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

json_json_body = json_body.to_dict()

return {
"method": "post",
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"follow_redirects": client.follow_redirects,
"json": json_json_body,
}


def _parse_response(
*, client: Client, response: httpx.Response
) -> Optional[Union[Any, ErrorResponse]]:
if response.status_code == HTTPStatus.OK:
response_200 = cast(Any, None)
return response_200
if response.status_code == HTTPStatus.BAD_REQUEST:
response_400 = ErrorResponse.from_dict(response.json())

return response_400
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(
*, client: Client, response: httpx.Response
) -> Response[Union[Any, ErrorResponse]]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
*,
client: Client,
json_body: TriggerContinueAsNewRequest,
) -> Response[Union[Any, ErrorResponse]]:
"""trigger ContinueAsNew for a workflow
Args:
json_body (TriggerContinueAsNewRequest):
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[Union[Any, ErrorResponse]]
"""

kwargs = _get_kwargs(
client=client,
json_body=json_body,
)

response = httpx.request(
verify=client.verify_ssl,
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
*,
client: Client,
json_body: TriggerContinueAsNewRequest,
) -> Optional[Union[Any, ErrorResponse]]:
"""trigger ContinueAsNew for a workflow
Args:
json_body (TriggerContinueAsNewRequest):
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Union[Any, ErrorResponse]
"""

return sync_detailed(
client=client,
json_body=json_body,
).parsed


async def asyncio_detailed(
*,
client: Client,
json_body: TriggerContinueAsNewRequest,
) -> Response[Union[Any, ErrorResponse]]:
"""trigger ContinueAsNew for a workflow
Args:
json_body (TriggerContinueAsNewRequest):
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[Union[Any, ErrorResponse]]
"""

kwargs = _get_kwargs(
client=client,
json_body=json_body,
)

async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
*,
client: Client,
json_body: TriggerContinueAsNewRequest,
) -> Optional[Union[Any, ErrorResponse]]:
"""trigger ContinueAsNew for a workflow
Args:
json_body (TriggerContinueAsNewRequest):
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Union[Any, ErrorResponse]
"""

return (
await asyncio_detailed(
client=client,
json_body=json_body,
)
).parsed
2 changes: 2 additions & 0 deletions iwf/iwf_api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .timer_command import TimerCommand
from .timer_result import TimerResult
from .timer_status import TimerStatus
from .trigger_continue_as_new_request import TriggerContinueAsNewRequest
from .wait_until_api_failure_policy import WaitUntilApiFailurePolicy
from .worker_error_response import WorkerErrorResponse
from .workflow_conditional_close import WorkflowConditionalClose
Expand Down Expand Up @@ -107,6 +108,7 @@
"TimerCommand",
"TimerResult",
"TimerStatus",
"TriggerContinueAsNewRequest",
"WaitUntilApiFailurePolicy",
"WorkerErrorResponse",
"WorkflowConditionalClose",
Expand Down
35 changes: 27 additions & 8 deletions iwf/iwf_api/models/inter_state_channel_command.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,66 @@
from typing import Any, Dict, List, Type, TypeVar
from typing import Any, Dict, List, Type, TypeVar, Union

import attr

from ..types import UNSET, Unset

T = TypeVar("T", bound="InterStateChannelCommand")


@attr.s(auto_attribs=True)
class InterStateChannelCommand:
"""
Attributes:
command_id (str):
channel_name (str):
command_id (Union[Unset, str]):
at_least (Union[Unset, int]):
at_most (Union[Unset, int]):
"""

command_id: str
channel_name: str
command_id: Union[Unset, str] = UNSET
at_least: Union[Unset, int] = UNSET
at_most: Union[Unset, int] = UNSET
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
command_id = self.command_id
channel_name = self.channel_name
command_id = self.command_id
at_least = self.at_least
at_most = self.at_most

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"commandId": command_id,
"channelName": channel_name,
}
)
if command_id is not UNSET:
field_dict["commandId"] = command_id
if at_least is not UNSET:
field_dict["atLeast"] = at_least
if at_most is not UNSET:
field_dict["atMost"] = at_most

return field_dict

@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
command_id = d.pop("commandId")

channel_name = d.pop("channelName")

command_id = d.pop("commandId", UNSET)

at_least = d.pop("atLeast", UNSET)

at_most = d.pop("atMost", UNSET)

inter_state_channel_command = cls(
command_id=command_id,
channel_name=channel_name,
command_id=command_id,
at_least=at_least,
at_most=at_most,
)

inter_state_channel_command.additional_properties = d
Expand Down
9 changes: 9 additions & 0 deletions iwf/iwf_api/models/persistence_loading_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ class PersistenceLoadingPolicy:
persistence_loading_type (Union[Unset, PersistenceLoadingType]):
partial_loading_keys (Union[Unset, List[str]]):
locking_keys (Union[Unset, List[str]]):
use_key_as_prefix (Union[Unset, bool]):
"""

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

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

use_key_as_prefix = self.use_key_as_prefix

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update({})
Expand All @@ -44,6 +48,8 @@ def to_dict(self) -> Dict[str, Any]:
field_dict["partialLoadingKeys"] = partial_loading_keys
if locking_keys is not UNSET:
field_dict["lockingKeys"] = locking_keys
if use_key_as_prefix is not UNSET:
field_dict["useKeyAsPrefix"] = use_key_as_prefix

return field_dict

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

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

use_key_as_prefix = d.pop("useKeyAsPrefix", UNSET)

persistence_loading_policy = cls(
persistence_loading_type=persistence_loading_type,
partial_loading_keys=partial_loading_keys,
locking_keys=locking_keys,
use_key_as_prefix=use_key_as_prefix,
)

persistence_loading_policy.additional_properties = d
Expand Down
1 change: 1 addition & 0 deletions iwf/iwf_api/models/persistence_loading_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class PersistenceLoadingType(str, Enum):
LOAD_ALL_WITHOUT_LOCKING = "LOAD_ALL_WITHOUT_LOCKING"
LOAD_ALL_WITH_PARTIAL_LOCK = "LOAD_ALL_WITH_PARTIAL_LOCK"
LOAD_NONE = "LOAD_NONE"
LOAD_PARTIAL_WITHOUT_LOCKING = "LOAD_PARTIAL_WITHOUT_LOCKING"
LOAD_PARTIAL_WITH_EXCLUSIVE_LOCK = "LOAD_PARTIAL_WITH_EXCLUSIVE_LOCK"
Expand Down
6 changes: 3 additions & 3 deletions iwf/iwf_api/models/retry_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def to_dict(self) -> Dict[str, Any]:
if maximum_attempts is not UNSET:
field_dict["maximumAttempts"] = maximum_attempts
if maximum_attempts_duration_seconds is not UNSET:
field_dict[
"maximumAttemptsDurationSeconds"
] = maximum_attempts_duration_seconds
field_dict["maximumAttemptsDurationSeconds"] = (
maximum_attempts_duration_seconds
)

return field_dict

Expand Down
Loading

0 comments on commit 2c77770

Please sign in to comment.