Skip to content

Commit d125ee4

Browse files
Ken LippoldKen Lippold
authored andcommitted
Renamed Job to DataConnection
1 parent 774bc13 commit d125ee4

File tree

12 files changed

+191
-90
lines changed

12 files changed

+191
-90
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = hydroserverpy
3-
version = 1.7.0b2
3+
version = 1.7.0b3
44
description = A Python client for managing HydroServer data
55
long_description_content_type = text/markdown
66
long_description = file: README.md

src/hydroserverpy/api/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
SensorService,
1313
DatastreamService,
1414
OrchestrationSystemService,
15-
JobService,
15+
DataConnectionService,
1616
TaskService,
1717
)
1818

@@ -191,10 +191,10 @@ def orchestrationsystems(self):
191191
return OrchestrationSystemService(self)
192192

193193
@property
194-
def jobs(self):
195-
"""Utilities for managing HydroServer ETL jobs."""
194+
def dataconnections(self):
195+
"""Utilities for managing HydroServer ETL data connections."""
196196

197-
return JobService(self)
197+
return DataConnectionService(self)
198198

199199
@property
200200
def tasks(self):

src/hydroserverpy/api/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .sta.thing import Thing
1414
from .sta.unit import Unit
1515
from .etl.orchestration_system import OrchestrationSystem
16-
from .etl.job import Job
16+
from .etl.data_connection import DataConnection
1717
from .etl.run import TaskRun
1818
from .etl.task import Task
1919
from .etl.mapping import TaskMapping

src/hydroserverpy/api/models/etl/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from .orchestration_system import OrchestrationSystem
2-
from .job import Job
2+
from .data_connection import DataConnection
33
from .task import Task
44
from .schedule import TaskSchedule
55
from .run import TaskRun
66

77
__all__ = [
88
"OrchestrationSystem",
9-
"Job",
9+
"DataConnection",
1010
"Task",
1111
"TaskSchedule",
1212
"TaskRun"
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import uuid
2-
from typing import ClassVar, List, TYPE_CHECKING
3-
from pydantic import Field, AliasPath
2+
from typing import ClassVar, List, Optional, TYPE_CHECKING
3+
from pydantic import Field, AliasPath, AliasChoices
44
from ..base import HydroServerBaseModel
55

66
if TYPE_CHECKING:
77
from hydroserverpy import HydroServer
88
from hydroserverpy.api.models import Workspace, Task
99

1010

11-
class Job(HydroServerBaseModel):
11+
class DataConnection(HydroServerBaseModel):
1212
name: str = Field(..., max_length=255)
13-
job_type: str = Field(..., max_length=255, alias="type")
14-
workspace_id: uuid.UUID
13+
data_connection_type: str = Field(..., max_length=255, alias="type")
14+
workspace_id: Optional[uuid.UUID] = Field(
15+
None, validation_alias=AliasChoices("workspaceId", AliasPath("workspace", "id"))
16+
)
1517
extractor_type: str = Field(..., max_length=255, validation_alias=AliasPath("extractor", "type"))
1618
extractor_settings: dict = Field(default_factory=dict, validation_alias=AliasPath("extractor", "settings"))
1719
transformer_type: str = Field(..., max_length=255, validation_alias=AliasPath("transformer", "type"))
@@ -21,7 +23,7 @@ class Job(HydroServerBaseModel):
2123

2224
_editable_fields: ClassVar[set[str]] = {
2325
"name",
24-
"job_type",
26+
"data_connection_type",
2527
"extractor_type",
2628
"extractor_settings",
2729
"transformer_type",
@@ -31,18 +33,18 @@ class Job(HydroServerBaseModel):
3133
}
3234

3335
def __init__(self, client: "HydroServer", **data):
34-
super().__init__(client=client, service=client.jobs, **data)
36+
super().__init__(client=client, service=client.dataconnections, **data)
3537

3638
self._workspace = None
3739
self._tasks = None
3840

3941
@classmethod
4042
def get_route(cls):
41-
return "etl-jobs"
43+
return "etl-data-connections"
4244

4345
@property
4446
def workspace(self) -> "Workspace":
45-
"""The workspace this ETL job belongs to."""
47+
"""The workspace this ETL data connection belongs to."""
4648

4749
if self._workspace is None and self.workspace_id:
4850
self._workspace = self.client.workspaces.get(uid=self.workspace_id)
@@ -51,11 +53,11 @@ def workspace(self) -> "Workspace":
5153

5254
@property
5355
def tasks(self) -> List["Task"]:
54-
"""The ETL tasks associated with this ETL job."""
56+
"""The ETL tasks associated with this ETL data connection."""
5557

5658
if self._tasks is None:
5759
self._tasks = self.client.tasks.list(
58-
job=self.uid, fetch_all=True
60+
data_connection=self.uid, fetch_all=True
5961
).items
6062

6163
return self._tasks

src/hydroserverpy/api/models/etl/orchestration_system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import uuid
2-
from typing import ClassVar, List, TYPE_CHECKING
2+
from typing import ClassVar, List, Optional, TYPE_CHECKING
33
from pydantic import Field
44
from ..base import HydroServerBaseModel
55

@@ -11,7 +11,7 @@
1111
class OrchestrationSystem(HydroServerBaseModel):
1212
name: str = Field(..., max_length=255)
1313
orchestration_system_type: str = Field(..., max_length=255, alias="type")
14-
workspace_id: uuid.UUID
14+
workspace_id: Optional[uuid.UUID] = None
1515

1616
_editable_fields: ClassVar[set[str]] = {"name", "orchestration_system_type"}
1717

Lines changed: 113 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
from __future__ import annotations
22
from functools import cached_property
33
import uuid
4-
from typing import ClassVar, TYPE_CHECKING, List, Optional
5-
from pydantic import Field
4+
from typing import ClassVar, TYPE_CHECKING, List, Optional, Literal, Union
5+
from datetime import datetime
6+
from pydantic import Field, AliasPath, AliasChoices
67
from ..base import HydroServerBaseModel
78
from .orchestration_system import OrchestrationSystem
8-
from .job import Job
9-
from .schedule import TaskSchedule
9+
from .data_connection import DataConnection
1010
from .run import TaskRun
11-
from .mapping import TaskMapping
1211

1312

1413
if TYPE_CHECKING:
@@ -21,21 +20,39 @@ class Task(HydroServerBaseModel):
2120
extractor_settings: dict = Field(default_factory=dict, alias="extractorSettings")
2221
transformer_settings: dict = Field(default_factory=dict, alias="transformerSettings")
2322
loader_settings: dict = Field(default_factory=dict, alias="loaderSettings")
24-
job_id: uuid.UUID
25-
orchestration_system_id: Optional[uuid.UUID] = None
26-
workspace_id: uuid.UUID
27-
schedule: Optional[TaskSchedule] = None
28-
latest_run: TaskRun
29-
mappings: List[TaskMapping]
23+
data_connection_id: uuid.UUID = Field(
24+
None, validation_alias=AliasChoices("dataConnectionId", AliasPath("dataConnection", "id"))
25+
)
26+
orchestration_system_id: uuid.UUID = Field(
27+
None, validation_alias=AliasChoices("orchestrationSystemId", AliasPath("orchestrationSystem", "id"))
28+
)
29+
workspace_id: uuid.UUID = Field(
30+
None, validation_alias=AliasChoices("workspaceId", AliasPath("workspace", "id"))
31+
)
32+
start_time: Optional[datetime] = Field(None, validation_alias=AliasPath("schedule", "startTime"))
33+
next_run_at: Optional[datetime] = Field(None, validation_alias=AliasPath("schedule", "nextRunAt"))
34+
paused: bool = Field(False, validation_alias=AliasPath("schedule", "paused"))
35+
interval: Optional[int] = Field(None, gt=0, validation_alias=AliasPath("schedule", "interval"))
36+
interval_period: Optional[Literal["minutes", "hours", "days"]] = Field(
37+
None, validation_alias=AliasPath("schedule", "intervalPeriod")
38+
)
39+
crontab: Optional[str] = Field(None, validation_alias=AliasPath("schedule", "crontab"))
40+
latest_run: Optional[TaskRun] = None
41+
mappings: List[dict]
3042

3143
_editable_fields: ClassVar[set[str]] = {
3244
"name",
3345
"extractor_settings",
3446
"transformer_settings",
3547
"loader_settings",
36-
"job_id",
48+
"data_connection_id",
3749
"orchestration_system_id",
38-
"schedule",
50+
"start_time",
51+
"next_run_at",
52+
"paused",
53+
"interval",
54+
"interval_period",
55+
"crontab",
3956
"mappings"
4057
}
4158

@@ -51,12 +68,91 @@ def workspace(self) -> Workspace:
5168
return self.client.workspaces.get(uid=self.workspace_id)
5269

5370
@cached_property
54-
def orchestration_system(self) -> OrchestrationSystem:
71+
def orchestration_system(self) -> Optional[OrchestrationSystem]:
5572
return self.client.orchestrationsystems.get(uid=self.orchestration_system_id)
5673

5774
@cached_property
58-
def job(self) -> Job:
59-
return self.client.jobs.get(uid=self.job_id)
75+
def data_connection(self) -> Optional[DataConnection]:
76+
return self.client.dataconnections.get(uid=self.data_connection_id)
77+
78+
def get_task_runs(
79+
self,
80+
page: int = ...,
81+
page_size: int = 100,
82+
order_by: List[str] = ...,
83+
status: str = ...,
84+
started_at_max: datetime = ...,
85+
started_at_min: datetime = ...,
86+
finished_at_max: datetime = ...,
87+
finished_at_min: datetime = ...,
88+
):
89+
"""Get a collection of task runs associated with this task."""
90+
91+
return self.client.tasks.get_task_runs(
92+
uid=self.uid,
93+
page=page,
94+
page_size=page_size,
95+
order_by=order_by,
96+
status=status,
97+
started_at_max=started_at_max,
98+
started_at_min=started_at_min,
99+
finished_at_max=finished_at_max,
100+
finished_at_min=finished_at_min,
101+
)
102+
103+
def create_task_run(
104+
self,
105+
status: Literal["RUNNING", "SUCCESS", "FAILURE"],
106+
started_at: datetime,
107+
finished_at: datetime = ...,
108+
result: dict = ...,
109+
):
110+
"""Create a new task run for this task."""
111+
112+
return self.client.tasks.create_task_run(
113+
uid=self.uid,
114+
status=status,
115+
started_at=started_at,
116+
finished_at=finished_at,
117+
result=result,
118+
)
119+
120+
def get_task_run(
121+
self,
122+
uid: Union[uuid.UUID, str],
123+
):
124+
"""Get a task run record for this task."""
125+
126+
return self.client.tasks.get_task_run(uid=self.uid, task_run_id=uid)
127+
128+
def update_task_run(
129+
self,
130+
uid: Union[uuid.UUID, str],
131+
status: Literal["RUNNING", "SUCCESS", "FAILURE"] = ...,
132+
started_at: datetime = ...,
133+
finished_at: datetime = ...,
134+
result: dict = ...,
135+
):
136+
"""Update a task run record of this task."""
137+
138+
return self.client.tasks.update_task_run(
139+
uid=self.uid,
140+
task_run_id=uid,
141+
status=status,
142+
started_at=started_at,
143+
finished_at=finished_at,
144+
result=result,
145+
)
146+
147+
def delete_task_run(
148+
self,
149+
uid: Union[uuid.UUID, str],
150+
):
151+
"""Delete a task run record of this task."""
152+
153+
return self.client.tasks.delete_task_run(uid=self.uid, task_run_id=uid)
60154

61155
def run(self):
62-
""""""
156+
"""Run this task."""
157+
158+
return self.client.tasks.run(uid=self.uid)

src/hydroserverpy/api/models/iam/workspace.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Datastream,
2121
OrchestrationSystem,
2222
Task,
23-
Job,
23+
DataConnection,
2424
)
2525

2626

@@ -50,7 +50,7 @@ def __init__(self, client: "HydroServer", **data):
5050
self._sensors = None
5151
self._datastreams = None
5252
self._orchestrationsystems = None
53-
self._jobs = None
53+
self._dataconnections = None
5454
self._tasks = None
5555

5656
@classmethod
@@ -166,13 +166,13 @@ def orchestrationsystems(self) -> List["OrchestrationSystem"]:
166166
return self._orchestrationsystems
167167

168168
@property
169-
def jobs(self) -> List["Job"]:
170-
"""The ETL jobs associated with this workspace."""
169+
def dataconnections(self) -> List["DataConnection"]:
170+
"""The ETL data connections associated with this workspace."""
171171

172-
if self._jobs is None:
173-
self._jobs = self.client.jobs.list(workspace=self.uid, fetch_all=True).items
172+
if self._dataconnections is None:
173+
self._dataconnections = self.client.dataconnections.list(workspace=self.uid, fetch_all=True).items
174174

175-
return self._jobs
175+
return self._dataconnections
176176

177177
@property
178178
def tasks(self) -> List["Task"]:

src/hydroserverpy/api/services/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
from .sta.sensor import SensorService
99
from .sta.datastream import DatastreamService
1010
from .etl.orchestration_system import OrchestrationSystemService
11-
from .etl.job import JobService
11+
from .etl.data_connection import DataConnectionService
1212
from .etl.task import TaskService

0 commit comments

Comments
 (0)