From fc55acee9e02c505d9be74639bde1e4e230fe273 Mon Sep 17 00:00:00 2001 From: gabriel ruttner Date: Tue, 10 Sep 2024 12:39:34 -0400 Subject: [PATCH] fix: gen --- examples/programatic_replay/script.py | 18 +- hatchet | 2 +- hatchet_sdk/clients/rest/__init__.py | 1 - hatchet_sdk/clients/rest/api/__init__.py | 1 - .../clients/rest/api/workflow_run_api.py | 575 ++++++++++++++++++ hatchet_sdk/clients/rest_client.py | 17 + 6 files changed, 607 insertions(+), 7 deletions(-) diff --git a/examples/programatic_replay/script.py b/examples/programatic_replay/script.py index edb5d685..0c1c06a3 100644 --- a/examples/programatic_replay/script.py +++ b/examples/programatic_replay/script.py @@ -1,3 +1,5 @@ +import asyncio + from dotenv import load_dotenv from hatchet_sdk import Hatchet, WorkflowRunStatus @@ -6,9 +8,17 @@ hatchet = Hatchet(debug=True) -if __name__ == "__main__": - # Look up the failed workflow runs - failed = hatchet.rest.events_list(statuses=[WorkflowRunStatus.FAILED], limit=3) +async def main(): + # Look up the failed workflow runs + failed = await hatchet.rest.aio.workflow_run_list( + statuses=[WorkflowRunStatus.FAILED], limit=3 + ) # Replay the failed workflow runs - retried = hatchet.rest.events_replay(failed) + retried = await hatchet.rest.aio.workflow_run_replay( + workflow_run_ids=[run.metadata.id for run in failed.rows] + ) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/hatchet b/hatchet index 91e68f97..460438ab 160000 --- a/hatchet +++ b/hatchet @@ -1 +1 @@ -Subproject commit 91e68f978c9d7985b71026e682fd461edacc5379 +Subproject commit 460438ab22ba82aeff4a7aad377b3e66abea2e1d diff --git a/hatchet_sdk/clients/rest/__init__.py b/hatchet_sdk/clients/rest/__init__.py index de23ce32..fa26fa87 100644 --- a/hatchet_sdk/clients/rest/__init__.py +++ b/hatchet_sdk/clients/rest/__init__.py @@ -32,7 +32,6 @@ from hatchet_sdk.clients.rest.api.worker_api import WorkerApi from hatchet_sdk.clients.rest.api.workflow_api import WorkflowApi from hatchet_sdk.clients.rest.api.workflow_run_api import WorkflowRunApi -from hatchet_sdk.clients.rest.api.workflow_runs_api import WorkflowRunsApi from hatchet_sdk.clients.rest.api_client import ApiClient # import ApiClient diff --git a/hatchet_sdk/clients/rest/api/__init__.py b/hatchet_sdk/clients/rest/api/__init__.py index 718a6534..bc8c788d 100644 --- a/hatchet_sdk/clients/rest/api/__init__.py +++ b/hatchet_sdk/clients/rest/api/__init__.py @@ -16,4 +16,3 @@ from hatchet_sdk.clients.rest.api.worker_api import WorkerApi from hatchet_sdk.clients.rest.api.workflow_api import WorkflowApi from hatchet_sdk.clients.rest.api.workflow_run_api import WorkflowRunApi -from hatchet_sdk.clients.rest.api.workflow_runs_api import WorkflowRunsApi diff --git a/hatchet_sdk/clients/rest/api/workflow_run_api.py b/hatchet_sdk/clients/rest/api/workflow_run_api.py index c0f22759..41231aa4 100644 --- a/hatchet_sdk/clients/rest/api/workflow_run_api.py +++ b/hatchet_sdk/clients/rest/api/workflow_run_api.py @@ -19,6 +19,12 @@ from hatchet_sdk.clients.rest.api_client import ApiClient, RequestSerialized from hatchet_sdk.clients.rest.api_response import ApiResponse +from hatchet_sdk.clients.rest.models.replay_workflow_runs_request import ( + ReplayWorkflowRunsRequest, +) +from hatchet_sdk.clients.rest.models.replay_workflow_runs_response import ( + ReplayWorkflowRunsResponse, +) from hatchet_sdk.clients.rest.models.trigger_workflow_run_request import ( TriggerWorkflowRunRequest, ) @@ -669,3 +675,572 @@ def _workflow_run_create_serialize( _host=_host, _request_auth=_request_auth, ) + + @validate_call + async def workflow_run_get_input( + self, + workflow_run: Annotated[ + str, + Field( + min_length=36, + strict=True, + max_length=36, + description="The workflow run id", + ), + ], + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> Dict[str, object]: + """Get workflow run input + + Get the input for a workflow run. + + :param workflow_run: The workflow run id (required) + :type workflow_run: str + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._workflow_run_get_input_serialize( + workflow_run=workflow_run, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "Dict[str, object]", + "400": "APIErrors", + "403": "APIErrors", + "404": "APIErrors", + } + response_data = await self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + await response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ).data + + @validate_call + async def workflow_run_get_input_with_http_info( + self, + workflow_run: Annotated[ + str, + Field( + min_length=36, + strict=True, + max_length=36, + description="The workflow run id", + ), + ], + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> ApiResponse[Dict[str, object]]: + """Get workflow run input + + Get the input for a workflow run. + + :param workflow_run: The workflow run id (required) + :type workflow_run: str + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._workflow_run_get_input_serialize( + workflow_run=workflow_run, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "Dict[str, object]", + "400": "APIErrors", + "403": "APIErrors", + "404": "APIErrors", + } + response_data = await self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + await response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ) + + @validate_call + async def workflow_run_get_input_without_preload_content( + self, + workflow_run: Annotated[ + str, + Field( + min_length=36, + strict=True, + max_length=36, + description="The workflow run id", + ), + ], + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> RESTResponseType: + """Get workflow run input + + Get the input for a workflow run. + + :param workflow_run: The workflow run id (required) + :type workflow_run: str + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._workflow_run_get_input_serialize( + workflow_run=workflow_run, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "Dict[str, object]", + "400": "APIErrors", + "403": "APIErrors", + "404": "APIErrors", + } + response_data = await self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + return response_data.response + + def _workflow_run_get_input_serialize( + self, + workflow_run, + _request_auth, + _content_type, + _headers, + _host_index, + ) -> RequestSerialized: + + _host = None + + _collection_formats: Dict[str, str] = {} + + _path_params: Dict[str, str] = {} + _query_params: List[Tuple[str, str]] = [] + _header_params: Dict[str, Optional[str]] = _headers or {} + _form_params: List[Tuple[str, str]] = [] + _files: Dict[str, Union[str, bytes]] = {} + _body_params: Optional[bytes] = None + + # process the path parameters + if workflow_run is not None: + _path_params["workflow-run"] = workflow_run + # process the query parameters + # process the header parameters + # process the form parameters + # process the body parameter + + # set the HTTP header `Accept` + _header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) + + # authentication setting + _auth_settings: List[str] = ["cookieAuth", "bearerAuth"] + + return self.api_client.param_serialize( + method="GET", + resource_path="/api/v1/workflow-runs/{workflow-run}/input", + path_params=_path_params, + query_params=_query_params, + header_params=_header_params, + body=_body_params, + post_params=_form_params, + files=_files, + auth_settings=_auth_settings, + collection_formats=_collection_formats, + _host=_host, + _request_auth=_request_auth, + ) + + @validate_call + async def workflow_run_update_replay( + self, + tenant: Annotated[ + str, + Field( + min_length=36, strict=True, max_length=36, description="The tenant id" + ), + ], + replay_workflow_runs_request: Annotated[ + ReplayWorkflowRunsRequest, + Field(description="The workflow run ids to replay"), + ], + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> ReplayWorkflowRunsResponse: + """Replay workflow runs + + Replays a list of workflow runs. + + :param tenant: The tenant id (required) + :type tenant: str + :param replay_workflow_runs_request: The workflow run ids to replay (required) + :type replay_workflow_runs_request: ReplayWorkflowRunsRequest + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._workflow_run_update_replay_serialize( + tenant=tenant, + replay_workflow_runs_request=replay_workflow_runs_request, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "ReplayWorkflowRunsResponse", + "400": "APIErrors", + "403": "APIErrors", + "429": "APIErrors", + } + response_data = await self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + await response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ).data + + @validate_call + async def workflow_run_update_replay_with_http_info( + self, + tenant: Annotated[ + str, + Field( + min_length=36, strict=True, max_length=36, description="The tenant id" + ), + ], + replay_workflow_runs_request: Annotated[ + ReplayWorkflowRunsRequest, + Field(description="The workflow run ids to replay"), + ], + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> ApiResponse[ReplayWorkflowRunsResponse]: + """Replay workflow runs + + Replays a list of workflow runs. + + :param tenant: The tenant id (required) + :type tenant: str + :param replay_workflow_runs_request: The workflow run ids to replay (required) + :type replay_workflow_runs_request: ReplayWorkflowRunsRequest + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._workflow_run_update_replay_serialize( + tenant=tenant, + replay_workflow_runs_request=replay_workflow_runs_request, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "ReplayWorkflowRunsResponse", + "400": "APIErrors", + "403": "APIErrors", + "429": "APIErrors", + } + response_data = await self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + await response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ) + + @validate_call + async def workflow_run_update_replay_without_preload_content( + self, + tenant: Annotated[ + str, + Field( + min_length=36, strict=True, max_length=36, description="The tenant id" + ), + ], + replay_workflow_runs_request: Annotated[ + ReplayWorkflowRunsRequest, + Field(description="The workflow run ids to replay"), + ], + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> RESTResponseType: + """Replay workflow runs + + Replays a list of workflow runs. + + :param tenant: The tenant id (required) + :type tenant: str + :param replay_workflow_runs_request: The workflow run ids to replay (required) + :type replay_workflow_runs_request: ReplayWorkflowRunsRequest + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._workflow_run_update_replay_serialize( + tenant=tenant, + replay_workflow_runs_request=replay_workflow_runs_request, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "ReplayWorkflowRunsResponse", + "400": "APIErrors", + "403": "APIErrors", + "429": "APIErrors", + } + response_data = await self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + return response_data.response + + def _workflow_run_update_replay_serialize( + self, + tenant, + replay_workflow_runs_request, + _request_auth, + _content_type, + _headers, + _host_index, + ) -> RequestSerialized: + + _host = None + + _collection_formats: Dict[str, str] = {} + + _path_params: Dict[str, str] = {} + _query_params: List[Tuple[str, str]] = [] + _header_params: Dict[str, Optional[str]] = _headers or {} + _form_params: List[Tuple[str, str]] = [] + _files: Dict[str, Union[str, bytes]] = {} + _body_params: Optional[bytes] = None + + # process the path parameters + if tenant is not None: + _path_params["tenant"] = tenant + # process the query parameters + # process the header parameters + # process the form parameters + # process the body parameter + if replay_workflow_runs_request is not None: + _body_params = replay_workflow_runs_request + + # set the HTTP header `Accept` + _header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) + + # set the HTTP header `Content-Type` + if _content_type: + _header_params["Content-Type"] = _content_type + else: + _default_content_type = self.api_client.select_header_content_type( + ["application/json"] + ) + if _default_content_type is not None: + _header_params["Content-Type"] = _default_content_type + + # authentication setting + _auth_settings: List[str] = ["cookieAuth", "bearerAuth"] + + return self.api_client.param_serialize( + method="POST", + resource_path="/api/v1/tenants/{tenant}/workflow-runs/replay", + path_params=_path_params, + query_params=_query_params, + header_params=_header_params, + body=_body_params, + post_params=_form_params, + files=_files, + auth_settings=_auth_settings, + collection_formats=_collection_formats, + _host=_host, + _request_auth=_request_auth, + ) diff --git a/hatchet_sdk/clients/rest_client.py b/hatchet_sdk/clients/rest_client.py index 80659d43..b3d502e0 100644 --- a/hatchet_sdk/clients/rest_client.py +++ b/hatchet_sdk/clients/rest_client.py @@ -8,6 +8,7 @@ from hatchet_sdk.clients.rest.api.step_run_api import StepRunApi from hatchet_sdk.clients.rest.api.workflow_api import WorkflowApi from hatchet_sdk.clients.rest.api.workflow_run_api import WorkflowRunApi +from hatchet_sdk.clients.rest.api.workflow_runs_api import WorkflowRunsApi from hatchet_sdk.clients.rest.api_client import ApiClient from hatchet_sdk.clients.rest.configuration import Configuration from hatchet_sdk.clients.rest.models import TriggerWorkflowRunRequest @@ -23,6 +24,12 @@ ) from hatchet_sdk.clients.rest.models.log_line_order_by_field import LogLineOrderByField from hatchet_sdk.clients.rest.models.replay_event_request import ReplayEventRequest +from hatchet_sdk.clients.rest.models.replay_workflow_runs_request import ( + ReplayWorkflowRunsRequest, +) +from hatchet_sdk.clients.rest.models.replay_workflow_runs_response import ( + ReplayWorkflowRunsResponse, +) from hatchet_sdk.clients.rest.models.workflow import Workflow from hatchet_sdk.clients.rest.models.workflow_kind import WorkflowKind from hatchet_sdk.clients.rest.models.workflow_list import WorkflowList @@ -154,6 +161,16 @@ async def workflow_run_get(self, workflow_run_id: str) -> WorkflowRun: workflow_run=workflow_run_id, ) + async def workflow_run_replay( + self, workflow_run_ids: list[str] + ) -> ReplayWorkflowRunsResponse: + return await self.workflow_run_api.workflow_run_update_replay( + tenant=self.tenant_id, + replay_workflow_runs_request=ReplayWorkflowRunsRequest( + workflow_run_ids=workflow_run_ids, + ), + ) + async def workflow_run_cancel( self, workflow_run_id: str ) -> WorkflowRunCancel200Response: