Skip to content

Commit

Permalink
feat: add metadata to workflow triggers (#2002)
Browse files Browse the repository at this point in the history
Co-authored-by: Håkon V. Treider <[email protected]>
  • Loading branch information
nodegard and haakonvt authored Nov 19, 2024
1 parent 03a073d commit 0691b84
Show file tree
Hide file tree
Showing 7 changed files with 635 additions and 660 deletions.
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,29 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [7.67.0] - 2023-11-19
## [7.67.1] - 2024-11-19
### Added
- Workflow triggers support metadata field
### Fixed
- Workflow description is optional

## [7.67.0] - 2024-11-19
### Added
- Convenience method `from_alias` to the UnitsAPI (`client.units.from_alias`) to help with looking up
units by their aliases (similarity search is supported).

## [7.66.1] - 2023-11-18
## [7.66.1] - 2024-11-18
### Removed
- The Core Data Model (v1) is now considered stable and the alpha warning has been removed.
- Usage of `instance_id` in the FilesAPI is considered stable and the alpha warning has been removed.

## [7.66.0] - 2023-11-15
## [7.66.0] - 2024-11-15
### Added
- User's trying to access a CDF project they do not have access to, will now be met with a more helpful
exception: `CogniteProjectAccessError` will be raised and accessible projects on the given cluser will
be listed, rather than just "401 - Unauthorized".

## [7.65.1] - 2023-11-14
## [7.65.1] - 2024-11-14
### Added
- Workflows now support data sets

Expand Down
9 changes: 5 additions & 4 deletions cognite/client/_api/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def upsert(
"""`Create or update a trigger for a workflow. <https://api-docs.cognite.com/20230101/tag/Workflow-triggers/operation/CreateOrUpdateTriggers>`_
Args:
workflow_trigger (WorkflowTriggerUpsert): The workflow trigger specitification.
workflow_trigger (WorkflowTriggerUpsert): The workflow trigger specification.
client_credentials (ClientCredentials | dict | None): Specific credentials that should be used to trigger the workflow execution. When passed will take precedence over the current credentials.
Returns:
WorkflowTrigger: The created or updated workflow trigger specification.
WorkflowTrigger: The created or updated workflow trigger specification.
Examples:
Expand All @@ -83,6 +83,7 @@ def upsert(
... workflow_external_id="my_workflow",
... workflow_version="1",
... input={"a": 1, "b": 2},
... metadata={"key": "value"},
... )
... )
Expand Down Expand Up @@ -133,7 +134,7 @@ def create(
This method is deprecated, use '.upsert' instead. It will be completely removed October 2024.
Args:
workflow_trigger (WorkflowTriggerCreate): The workflow trigger specitification.
workflow_trigger (WorkflowTriggerCreate): The workflow trigger specification.
client_credentials (ClientCredentials | dict | None): Specific credentials that should be used to trigger the workflow execution. When passed will take precedence over the current credentials.
Returns:
Expand Down Expand Up @@ -507,7 +508,7 @@ def cancel(self, id: str, reason: str | None) -> WorkflowExecution:
>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.workflows.executions.run("foo", "1")
>>> client.workflows.executions.cancel(id="foo", reason="test cancelation")
>>> client.workflows.executions.cancel(id="foo", reason="test cancellation")
"""
response = self._post(
url_path=f"{self._RESOURCE_PATH}/{id}/cancel",
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations

__version__ = "7.67.0"
__version__ = "7.67.1"
__api_subversion__ = "20230101"
26 changes: 20 additions & 6 deletions cognite/client/data_classes/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,14 +736,14 @@ class WorkflowDefinitionCore(WriteableCogniteResource["WorkflowDefinitionUpsert"
tasks (list[WorkflowTask]): The tasks of the workflow definition.
description (str | None): The description of the workflow definition. Note that when updating a workflow definition
description, it will always be overwritten also if it is set to None. Meaning if the
wokflow definition already has a description, and you want to keep it, you need to provide
workflow definition already has a description, and you want to keep it, you need to provide
the description when updating it.
"""

def __init__(
self,
tasks: list[WorkflowTask],
description: str | None,
description: str | None = None,
) -> None:
self.tasks = tasks
self.description = description
Expand All @@ -764,22 +764,22 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]:

class WorkflowDefinitionUpsert(WorkflowDefinitionCore):
"""
This class represents a workflow definition. This represents the write/update version of a workflow definiton.
This class represents a workflow definition. This represents the write/update version of a workflow definition.
A workflow definition defines the tasks and order/dependencies of these tasks.
Args:
tasks (list[WorkflowTask]): The tasks of the workflow definition.
description (str | None): The description of the workflow definition. Note that when updating a workflow definition
description, it will always be overwritten also if it is set to None. Meaning if the
wokflow definition already has a description, and you want to keep it, you need to provide
workflow definition already has a description, and you want to keep it, you need to provide
the description when updating it.
"""

def __init__(
self,
tasks: list[WorkflowTask],
description: str | None,
description: str | None = None,
) -> None:
super().__init__(tasks, description)

Expand All @@ -803,7 +803,7 @@ def as_write(self) -> WorkflowDefinitionUpsert:

class WorkflowDefinition(WorkflowDefinitionCore):
"""
This class represents a workflow definition. This represents the read version of a workflow definiton.
This class represents a workflow definition. This represents the read version of a workflow definition.
A workflow definition defines the tasks and order/dependencies of these tasks.
Expand Down Expand Up @@ -1352,6 +1352,7 @@ class WorkflowTriggerCore(WriteableCogniteResource["WorkflowTriggerUpsert"], ABC
workflow_external_id (str): The external ID of the workflow.
workflow_version (str): The version of the workflow.
input (dict | None): The input data of the workflow version trigger. Defaults to None.
metadata (dict | None): Application specific metadata. Defaults to None.
"""

def __init__(
Expand All @@ -1361,12 +1362,14 @@ def __init__(
workflow_external_id: str,
workflow_version: str,
input: dict | None = None,
metadata: dict | None = None,
) -> None:
self.external_id = external_id
self.trigger_rule = trigger_rule
self.workflow_external_id = workflow_external_id
self.workflow_version = workflow_version
self.input = input
self.metadata = metadata


class WorkflowTriggerUpsert(WorkflowTriggerCore):
Expand All @@ -1379,6 +1382,7 @@ class WorkflowTriggerUpsert(WorkflowTriggerCore):
workflow_external_id (str): The external ID of the workflow.
workflow_version (str): The version of the workflow.
input (dict | None): The input data of the workflow version trigger. Defaults to None.
metadata (dict | None): Application specific metadata. Defaults to None.
"""

def dump(self, camel_case: bool = True) -> dict[str, Any]:
Expand All @@ -1390,6 +1394,8 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]:
}
if self.input:
item["input"] = self.input
if self.metadata:
item["metadata"] = self.metadata
if camel_case:
return convert_all_keys_to_camel_case(item)
return item
Expand All @@ -1402,6 +1408,7 @@ def _load(cls, resource: dict, cognite_client: CogniteClient | None = None) -> W
workflow_version=resource["workflowVersion"],
trigger_rule=WorkflowTriggerRule._load(resource["triggerRule"]),
input=resource.get("input"),
metadata=resource.get("metadata"),
)

def as_write(self) -> WorkflowTriggerUpsert:
Expand All @@ -1422,6 +1429,7 @@ class WorkflowTrigger(WorkflowTriggerCore):
workflow_external_id (str): The external ID of the workflow.
workflow_version (str): The version of the workflow.
input (dict | None): The input data passed to the workflow when an execution is started. Defaults to None.
metadata (dict | None): Application specific metadata. Defaults to None.
created_time (int | None): The time when the workflow version trigger was created. Unix timestamp in milliseconds. Defaults to None.
last_updated_time (int | None): The time when the workflow version trigger was last updated. Unix timestamp in milliseconds. Defaults to None.
"""
Expand All @@ -1433,6 +1441,7 @@ def __init__(
workflow_external_id: str,
workflow_version: str,
input: dict | None = None,
metadata: dict | None = None,
created_time: int | None = None,
last_updated_time: int | None = None,
) -> None:
Expand All @@ -1442,6 +1451,7 @@ def __init__(
workflow_external_id=workflow_external_id,
workflow_version=workflow_version,
input=input,
metadata=metadata,
)
self.created_time = created_time
self.last_updated_time = last_updated_time
Expand All @@ -1455,6 +1465,8 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]:
}
if self.input:
item["input"] = self.input
if self.metadata:
item["metadata"] = self.metadata
if self.created_time:
item["created_time"] = self.created_time
if self.last_updated_time:
Expand All @@ -1471,6 +1483,7 @@ def _load(cls, resource: dict, cognite_client: CogniteClient | None = None) -> W
workflow_version=resource["workflowVersion"],
trigger_rule=WorkflowTriggerRule._load(resource["triggerRule"]),
input=resource.get("input"),
metadata=resource.get("metadata"),
created_time=resource.get("createdTime"),
last_updated_time=resource.get("lastUpdatedTime"),
)
Expand All @@ -1483,6 +1496,7 @@ def as_write(self) -> WorkflowTriggerUpsert:
workflow_external_id=self.workflow_external_id,
workflow_version=self.workflow_version,
input=self.input,
metadata=self.metadata,
)


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "cognite-sdk"

version = "7.67.0"
version = "7.67.1"
description = "Cognite Python SDK"
readme = "README.md"
documentation = "https://cognite-sdk-python.readthedocs-hosted.com"
Expand Down
Loading

0 comments on commit 0691b84

Please sign in to comment.