|
| 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 |
0 commit comments