|
28 | 28 |
|
29 | 29 | if TYPE_CHECKING: |
30 | 30 | from cognite.client import CogniteClient |
| 31 | +from zoneinfo import ZoneInfo |
31 | 32 |
|
32 | 33 | TaskStatus: TypeAlias = Literal[ |
33 | 34 | "in_progress", |
@@ -1415,16 +1416,30 @@ class WorkflowScheduledTriggerRule(WorkflowTriggerRule): |
1415 | 1416 |
|
1416 | 1417 | Args: |
1417 | 1418 | cron_expression (str): The cron specification for the scheduled trigger. |
| 1419 | + timezone (ZoneInfo | None): The timezone in which the scheduled trigger should be evaluated. |
| 1420 | + If not provided, UTC will be used as the default timezone on the server side. |
1418 | 1421 | """ |
1419 | 1422 |
|
1420 | 1423 | _trigger_type = "schedule" |
1421 | 1424 |
|
1422 | | - def __init__(self, cron_expression: str) -> None: |
| 1425 | + def __init__(self, cron_expression: str, timezone: ZoneInfo | None = None) -> None: |
1423 | 1426 | self.cron_expression = cron_expression |
| 1427 | + self.timezone = timezone |
| 1428 | + |
| 1429 | + def dump(self, camel_case: bool = True) -> dict[str, Any]: |
| 1430 | + # Override dump to handle timezone field specially: |
| 1431 | + # 1. Only include timezone key when it has a value (avoid "timezone": null) |
| 1432 | + # 2. Convert ZoneInfo object to its string key representation |
| 1433 | + item = super().dump(camel_case) |
| 1434 | + if self.timezone: |
| 1435 | + item["timezone"] = self.timezone.key |
| 1436 | + return item |
1424 | 1437 |
|
1425 | 1438 | @classmethod |
1426 | 1439 | def _load_trigger(cls, data: dict) -> WorkflowScheduledTriggerRule: |
1427 | | - return cls(cron_expression=data["cronExpression"]) |
| 1440 | + # Convert timezone to ZoneInfo |
| 1441 | + timezone = ZoneInfo(data["timezone"]) if "timezone" in data else None |
| 1442 | + return cls(cron_expression=data["cronExpression"], timezone=timezone) |
1428 | 1443 |
|
1429 | 1444 |
|
1430 | 1445 | class WorkflowDataModelingTriggerRule(WorkflowTriggerRule): |
@@ -1525,6 +1540,7 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: |
1525 | 1540 | "workflow_external_id": self.workflow_external_id, |
1526 | 1541 | "workflow_version": self.workflow_version, |
1527 | 1542 | } |
| 1543 | + |
1528 | 1544 | if self.input: |
1529 | 1545 | item["input"] = self.input |
1530 | 1546 | if self.metadata: |
|
0 commit comments