diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f39b5f2c5..e3667cdec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ --- repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.2 + rev: v0.6.3 hooks: - id: ruff args: diff --git a/CHANGELOG.md b/CHANGELOG.md index c899e45cc..00c6cbaa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,10 +17,14 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. -## [7.56.0] - 2024-08-30 +## [7.56.0] - 2024-09-02 ### Added - Support for referencing files by instance id when running diagrams.detect +## [7.55.2] - 2024-08-29 +### Fixed +- Turn workflow_orchestration into data_workflows and add trigger doc, fix attribute names in data classes + ## [7.55.1] - 2024-08-29 ### Fixed - Missing exports for workflow triggers diff --git a/cognite/client/data_classes/contextualization.py b/cognite/client/data_classes/contextualization.py index 8e9669c65..ad056330c 100644 --- a/cognite/client/data_classes/contextualization.py +++ b/cognite/client/data_classes/contextualization.py @@ -373,12 +373,13 @@ def __init__( raise ValueError("If the page range feature is used, both first page and last page must be set") def to_api_item(self) -> dict[str, str | int | dict[str, int] | dict[str, str]]: - if self.file_id is None and self.file_external_id is not None: + if self.file_id is None and self.file_external_id is not None and self.file_instance_id is None: item: dict[str, str | int | dict[str, int] | dict[str, str]] = {"fileExternalId": self.file_external_id} - if self.file_id is not None and self.file_external_id is None: + if self.file_id is not None and self.file_external_id is None and self.file_instance_id is None: item = {"fileId": self.file_id} - if self.file_instance_id is not None: + if self.file_id is None and self.file_external_id is None and self.file_instance_id is not None: item = {"fileInstanceId": self.file_instance_id.dump(include_instance_type=False)} + if self.first_page is not None and self.last_page is not None: item["pageRange"] = {"begin": self.first_page, "end": self.last_page} return item diff --git a/cognite/client/data_classes/workflows.py b/cognite/client/data_classes/workflows.py index 90410888f..26f13eb6e 100644 --- a/cognite/client/data_classes/workflows.py +++ b/cognite/client/data_classes/workflows.py @@ -1381,23 +1381,33 @@ class WorkflowTriggerRun(CogniteResource): def __init__( self, - trigger_external_id: str, - trigger_fire_time: int, + external_id: str, + fire_time: int, workflow_external_id: str, workflow_version: str, + workflow_execution_id: str, + status: Literal["success", "failed"], + reason_for_failure: str | None = None, ) -> None: - self.trigger_external_id = trigger_external_id - self.trigger_fire_time = trigger_fire_time + self.external_id = external_id + self.fire_time = fire_time self.workflow_external_id = workflow_external_id self.workflow_version = workflow_version + self.workflow_execution_id = workflow_execution_id + self.status = status + self.reason_for_failure = reason_for_failure def dump(self, camel_case: bool = True) -> dict[str, Any]: item = { - "trigger_external_id": self.trigger_external_id, - "trigger_fire_time": self.trigger_fire_time, + "external_id": self.external_id, + "fire_time": self.fire_time, "workflow_external_id": self.workflow_external_id, "workflow_version": self.workflow_version, + "workflow_execution_id": self.workflow_execution_id, + "status": self.status, } + if self.reason_for_failure: + item["reason_for_failure"] = self.reason_for_failure if camel_case: return convert_all_keys_to_camel_case(item) return item @@ -1405,10 +1415,13 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: @classmethod def _load(cls, resource: dict, cognite_client: CogniteClient | None = None) -> WorkflowTriggerRun: return cls( - trigger_external_id=resource["triggerExternalId"], - trigger_fire_time=resource["triggerFireTime"], + external_id=resource["externalId"], + fire_time=resource["fireTime"], workflow_external_id=resource["workflowExternalId"], workflow_version=resource["workflowVersion"], + workflow_execution_id=resource["workflowExecutionId"], + status=resource["status"], + reason_for_failure=resource.get("reasonForFailure"), ) diff --git a/docs/source/workflow_orchestration.rst b/docs/source/data_workflows.rst similarity index 76% rename from docs/source/workflow_orchestration.rst rename to docs/source/data_workflows.rst index 002395270..81bcc3a3e 100644 --- a/docs/source/workflow_orchestration.rst +++ b/docs/source/data_workflows.rst @@ -71,6 +71,23 @@ Update Status of Async Task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. automethod:: cognite.client._api.workflows.WorkflowTaskAPI.update +Workflow Triggers +------------------- +Create triggers for workflow executions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. automethod:: cognite.client._api.workflows.WorkflowTriggerAPI.create + +Delete triggers for workflow executions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. automethod:: cognite.client._api.workflows.WorkflowTriggerAPI.delete + +Get triggers for workflow executions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. automethod:: cognite.client._api.workflows.WorkflowTriggerAPI.get_triggers + +Get trigger run history for a workflow trigger +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. automethod:: cognite.client._api.workflows.WorkflowTriggerAPI.get_trigger_run_history Data Workflows data classes ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/source/index.rst b/docs/source/index.rst index 2c6883410..f8d2044fc 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -53,7 +53,7 @@ Contents data_organization transformations functions - workflow_orchestration + data_workflows unit_catalog filters deprecated diff --git a/poetry.lock b/poetry.lock index 43f6bc5e2..24b9b0b2c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -132,13 +132,13 @@ tzdata = ["tzdata"] [[package]] name = "certifi" -version = "2024.7.4" +version = "2024.8.30" description = "Python package for providing Mozilla's CA Bundle." optional = false python-versions = ">=3.6" files = [ - {file = "certifi-2024.7.4-py3-none-any.whl", hash = "sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90"}, - {file = "certifi-2024.7.4.tar.gz", hash = "sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b"}, + {file = "certifi-2024.8.30-py3-none-any.whl", hash = "sha256:922820b53db7a7257ffbda3f597266d435245903d80737e34f8a45ff3e3230d8"}, + {file = "certifi-2024.8.30.tar.gz", hash = "sha256:bec941d2aa8195e248a60b31ff9f0558284cf01a52591ceda73ea9afffd69fd9"}, ] [[package]] @@ -589,13 +589,13 @@ testing = ["hatch", "pre-commit", "pytest", "tox"] [[package]] name = "executing" -version = "2.0.1" +version = "2.1.0" description = "Get the currently executing AST node of a frame, and other information" optional = false -python-versions = ">=3.5" +python-versions = ">=3.8" files = [ - {file = "executing-2.0.1-py2.py3-none-any.whl", hash = "sha256:eac49ca94516ccc753f9fb5ce82603156e590b27525a8bc32cce8ae302eb61bc"}, - {file = "executing-2.0.1.tar.gz", hash = "sha256:35afe2ce3affba8ee97f2d69927fa823b08b472b7b994e36a52a964b93d16147"}, + {file = "executing-2.1.0-py2.py3-none-any.whl", hash = "sha256:8d63781349375b5ebccc3142f4b30350c0cd9c79f921cde38be2be4637e98eaf"}, + {file = "executing-2.1.0.tar.gz", hash = "sha256:8ea27ddd260da8150fa5a708269c4a10e76161e2496ec3e587da9e3c0fe4b9ab"}, ] [package.extras] @@ -1672,22 +1672,22 @@ wcwidth = "*" [[package]] name = "protobuf" -version = "5.27.4" +version = "5.28.0" description = "" optional = false python-versions = ">=3.8" files = [ - {file = "protobuf-5.27.4-cp310-abi3-win32.whl", hash = "sha256:10319748764b917a9a7cddef1582a0a9cd0f8f6d04e545c6236f7ccaf9b624d9"}, - {file = "protobuf-5.27.4-cp310-abi3-win_amd64.whl", hash = "sha256:f0c24374aaaf103f33662e4de7666a4a4280abebdb8a9f3f0f9b1d71b61174ec"}, - {file = "protobuf-5.27.4-cp38-abi3-macosx_10_9_universal2.whl", hash = "sha256:e85fed07013e5a0121efbaf1b14355fdc66f6e545f12fc5985b2882370410006"}, - {file = "protobuf-5.27.4-cp38-abi3-manylinux2014_aarch64.whl", hash = "sha256:d5a0e229061600842e57af4ff6a8522ede5280bcfa4fe7f3a1c20589377859a6"}, - {file = "protobuf-5.27.4-cp38-abi3-manylinux2014_x86_64.whl", hash = "sha256:25ba1f0633f73c3939f3b84e1636f3eb3bab7196952ebb83906d56945edd6aa8"}, - {file = "protobuf-5.27.4-cp38-cp38-win32.whl", hash = "sha256:565b051249a2f8270af04206dd4f3b73a02343e7d9e072aed57441b369b3467d"}, - {file = "protobuf-5.27.4-cp38-cp38-win_amd64.whl", hash = "sha256:e673f173cbac4e59c7817ed358e471e4c77aa9166986edf3e731156379a556c7"}, - {file = "protobuf-5.27.4-cp39-cp39-win32.whl", hash = "sha256:25169c7624d5a9e669fa6faff5a6e818f854346d51ee347b2284676beb9e85dd"}, - {file = "protobuf-5.27.4-cp39-cp39-win_amd64.whl", hash = "sha256:1fe7735902e84ce35c4152cf07981c176713935a8efad78cea547aae5f4f75cb"}, - {file = "protobuf-5.27.4-py3-none-any.whl", hash = "sha256:b97259641e8d38738eef34a173e51d2d53a453baab01a32477a64752d9ce59a3"}, - {file = "protobuf-5.27.4.tar.gz", hash = "sha256:eaa1016e353d8fc5bf08c8087e96eed15f5297aa52bb7ee1f533278bb3f3aad7"}, + {file = "protobuf-5.28.0-cp310-abi3-win32.whl", hash = "sha256:66c3edeedb774a3508ae70d87b3a19786445fe9a068dd3585e0cefa8a77b83d0"}, + {file = "protobuf-5.28.0-cp310-abi3-win_amd64.whl", hash = "sha256:6d7cc9e60f976cf3e873acb9a40fed04afb5d224608ed5c1a105db4a3f09c5b6"}, + {file = "protobuf-5.28.0-cp38-abi3-macosx_10_9_universal2.whl", hash = "sha256:532627e8fdd825cf8767a2d2b94d77e874d5ddb0adefb04b237f7cc296748681"}, + {file = "protobuf-5.28.0-cp38-abi3-manylinux2014_aarch64.whl", hash = "sha256:018db9056b9d75eb93d12a9d35120f97a84d9a919bcab11ed56ad2d399d6e8dd"}, + {file = "protobuf-5.28.0-cp38-abi3-manylinux2014_x86_64.whl", hash = "sha256:6206afcb2d90181ae8722798dcb56dc76675ab67458ac24c0dd7d75d632ac9bd"}, + {file = "protobuf-5.28.0-cp38-cp38-win32.whl", hash = "sha256:eef7a8a2f4318e2cb2dee8666d26e58eaf437c14788f3a2911d0c3da40405ae8"}, + {file = "protobuf-5.28.0-cp38-cp38-win_amd64.whl", hash = "sha256:d001a73c8bc2bf5b5c1360d59dd7573744e163b3607fa92788b7f3d5fefbd9a5"}, + {file = "protobuf-5.28.0-cp39-cp39-win32.whl", hash = "sha256:dde9fcaa24e7a9654f4baf2a55250b13a5ea701493d904c54069776b99a8216b"}, + {file = "protobuf-5.28.0-cp39-cp39-win_amd64.whl", hash = "sha256:853db610214e77ee817ecf0514e0d1d052dff7f63a0c157aa6eabae98db8a8de"}, + {file = "protobuf-5.28.0-py3-none-any.whl", hash = "sha256:510ed78cd0980f6d3218099e874714cdf0d8a95582e7b059b06cabad855ed0a0"}, + {file = "protobuf-5.28.0.tar.gz", hash = "sha256:dde74af0fa774fa98892209992295adbfb91da3fa98c8f67a88afe8f5a349add"}, ] [[package]] diff --git a/tests/tests_integration/test_api/test_data_workflows.py b/tests/tests_integration/test_api/test_data_workflows.py index 9a3c0f30b..7b87f44a7 100644 --- a/tests/tests_integration/test_api/test_data_workflows.py +++ b/tests/tests_integration/test_api/test_data_workflows.py @@ -253,7 +253,7 @@ def workflow_scheduled_trigger(cognite_client: CogniteClient, add_multiply_workf trigger = cognite_client.workflows.triggers.create( WorkflowTriggerCreate( external_id="integration_test-workflow-scheduled-trigger", - trigger_rule=WorkflowScheduledTriggerRule(cron_expression="0 0 * * *"), + trigger_rule=WorkflowScheduledTriggerRule(cron_expression="* * * * *"), workflow_external_id="integration_test-workflow-add_multiply", workflow_version="1", input={"a": 1, "b": 2}, @@ -490,7 +490,7 @@ def test_create_delete( ) -> None: assert workflow_scheduled_trigger is not None assert workflow_scheduled_trigger.external_id == "integration_test-workflow-scheduled-trigger" - assert workflow_scheduled_trigger.trigger_rule == WorkflowScheduledTriggerRule(cron_expression="0 0 * * *") + assert workflow_scheduled_trigger.trigger_rule == WorkflowScheduledTriggerRule(cron_expression="* * * * *") assert workflow_scheduled_trigger.workflow_external_id == "integration_test-workflow-add_multiply" assert workflow_scheduled_trigger.workflow_version == "1" assert workflow_scheduled_trigger.input == {"a": 1, "b": 2}