Skip to content

Commit

Permalink
merge, plus more robust to_api_item
Browse files Browse the repository at this point in the history
  • Loading branch information
Ola Liabøtrø committed Sep 2, 2024
2 parents 098dc3a + 95178fd commit 027a73e
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions cognite/client/data_classes/contextualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 21 additions & 8 deletions cognite/client/data_classes/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,34 +1381,47 @@ 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

@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"),
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Contents
data_organization
transformations
functions
workflow_orchestration
data_workflows
unit_catalog
filters
deprecated
Expand Down
38 changes: 19 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/tests_integration/test_api/test_data_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 027a73e

Please sign in to comment.