Skip to content

Commit

Permalink
Workflows API: support metadata (#1408)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddonukis authored Oct 6, 2023
1 parent 5808a78 commit 333a97e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [6.30.1] - 2023-10-06
### Added
- Support for metadata on Workflow executions. Set custom metadata when triggering a workflow (`workflows.executions.trigger()`). The metadata is included in results from `workflows.executions.list()` and `workflows.executions.retrieve_detailed()`.

## [6.30.0] - 2023-10-06
### Added
- Support for the UnitCatalog with the implementation `client.units`.

## [6.29.2] - 2023-10-04
### Fixed
- Calling some of the methods `assets.filter()`, `events.filter()`, `sequences.filter()`, `time_series.filter()` without a `sort` parameter could cause a `CogniteAPIError` with a 400 code. This is now fixed.
- Calling some of the methods `assets.filter()`, `events.filter()`, `sequences.filter()`, `time_series.filter()` without a `sort` parameter could cause a `CogniteAPIError` with a 400 code. This is now fixed.

## [6.29.1] - 2023-10-04
### Added
- Convenience method `to_text` on the `FunctionCallLog` class which simplifies printing out function call logs.

## [6.29.0] - 2023-10-04
### Added
- Added parameter `resolve_duplicate_file_names` to `client.files.download`.
- Added parameter `resolve_duplicate_file_names` to `client.files.download`.
This will keep all the files when downloading to local machine, even if they have the same name.

## [6.28.5] - 2023-10-03
Expand Down
7 changes: 5 additions & 2 deletions cognite/client/_api/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,15 @@ def trigger(
workflow_external_id: str,
version: str,
input: dict | None = None,
metadata: dict | None = None,
) -> WorkflowExecution:
"""`Trigger a workflow execution. <https://pr-2282.specs.preview.cogniteapp.com/20230101.json.html#tag/Workflow-Execution/operation/TriggerRunOfSpecificVersionOfWorkflow>`_
Args:
workflow_external_id (str): External id of the workflow.
version (str): Version of the workflow.
input (dict | None): The input to the workflow execution. This will be available for tasks that have specified it as an input with the strind "${workflow.input}"
See tip below for more information.
input (dict | None): The input to the workflow execution. This will be available for tasks that have specified it as an input with the string "${workflow.input}" See tip below for more information.
metadata (dict | None): Application specific metadata. Keys have a maximum length of 32 characters, values a maximum of 255, and there can be a maximum of 10 key-value pairs.
Tip:
The workflow input can be available in the workflow tasks. For example, if you have a Task with
Expand Down Expand Up @@ -189,6 +190,8 @@ def trigger(
body = {"authentication": {"nonce": nonce}}
if input is not None:
body["input"] = input
if metadata is not None:
body["metadata"] = metadata

response = self._post(
url_path=f"/workflows/{workflow_external_id}/versions/{version}/run",
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__ = "6.30.0"
__version__ = "6.30.1"
__api_subversion__ = "V20220125"
5 changes: 5 additions & 0 deletions cognite/client/data_classes/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ class WorkflowExecution(CogniteResource):
start_time (int | None): The start time of the workflow execution. Unix timestamp in milliseconds. Defaults to None.
end_time (int | None): The end time of the workflow execution. Unix timestamp in milliseconds. Defaults to None.
reason_for_incompletion (str | None): Provides the reason if the workflow did not complete successfully. Defaults to None.
metadata (dict | None): Application specific metadata.
"""

def __init__(
Expand All @@ -781,6 +782,7 @@ def __init__(
start_time: int | None = None,
end_time: int | None = None,
reason_for_incompletion: str | None = None,
metadata: dict | None = None,
) -> None:
self.id = id
self.workflow_external_id = workflow_external_id
Expand All @@ -790,6 +792,7 @@ def __init__(
self.start_time = start_time
self.end_time = end_time
self.reason_for_incompletion = reason_for_incompletion
self.metadata = metadata

def as_workflow_id(self) -> WorkflowVersionId:
return WorkflowVersionId(
Expand All @@ -812,6 +815,7 @@ def _load(cls, resource: dict | str, cognite_client: CogniteClient | None = None
start_time=resource.get("startTime"),
end_time=resource.get("endTime"),
reason_for_incompletion=resource.get("reasonForIncompletion"),
metadata=resource.get("metadata"),
)


Expand Down Expand Up @@ -913,6 +917,7 @@ def as_execution(self) -> WorkflowExecution:
start_time=self.start_time,
end_time=self.end_time,
reason_for_incompletion=self.reason_for_incompletion,
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 = "6.30.0"
version = "6.30.1"
description = "Cognite Python SDK"
readme = "README.md"
documentation = "https://cognite-sdk-python.readthedocs-hosted.com"
Expand Down

0 comments on commit 333a97e

Please sign in to comment.