-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
138 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import typing as t | ||
from dataclasses import dataclass | ||
from enum import Enum | ||
|
||
import cdf.injector as injector | ||
|
||
if t.TYPE_CHECKING: | ||
import dlt | ||
|
||
|
||
class ServiceLevelAgreement(Enum): | ||
"""An SLA to assign to a service or pipeline""" | ||
|
||
LOW = 1 | ||
MEDIUM = 2 | ||
HIGH = 3 | ||
CRITICAL = 4 | ||
|
||
|
||
@dataclass | ||
class Service: | ||
"""A service that the workspace provides.""" | ||
|
||
name: injector.DependencyKey | ||
dependency: injector.Dependency[t.Any] | ||
owner: str | ||
description: str = "No description provided" | ||
sla: ServiceLevelAgreement = ServiceLevelAgreement.MEDIUM | ||
|
||
def __post_init__(self): | ||
if self.sla not in ServiceLevelAgreement: | ||
raise ValueError(f"Invalid SLA: {self.sla}") | ||
|
||
def __str__(self): | ||
return f"{self.name} ({self.sla.name})" | ||
|
||
|
||
class _Service(t.TypedDict, total=False): | ||
"""A service type hint.""" | ||
|
||
name: injector.DependencyKey | ||
dependency: injector.Dependency[t.Any] | ||
owner: str | ||
description: str | ||
sla: ServiceLevelAgreement | ||
|
||
|
||
ServiceDef = t.Union[Service, _Service] | ||
|
||
|
||
@dataclass | ||
class Source: | ||
"""A dlt source that the workspace provides.""" | ||
|
||
name: str | ||
dependency: injector.Dependency[ | ||
"t.Union[t.Callable[..., dlt.sources.DltSource], dlt.sources.DltSource]" | ||
] | ||
owner: str | ||
description: str = "No description provided" | ||
sla: ServiceLevelAgreement = ServiceLevelAgreement.MEDIUM | ||
|
||
def __post_init__(self): | ||
if self.sla not in ServiceLevelAgreement: | ||
raise ValueError(f"Invalid SLA: {self.sla}") | ||
|
||
def __str__(self): | ||
return f"{self.name} ({self.sla.name})" | ||
|
||
|
||
class _Source(t.TypedDict, total=False): | ||
"""A source type hint.""" | ||
|
||
name: str | ||
dependency: injector.Dependency[ | ||
"t.Union[t.Callable[..., dlt.sources.DltSource], dlt.sources.DltSource]" | ||
] | ||
owner: str | ||
description: str | ||
sla: ServiceLevelAgreement | ||
|
||
|
||
SourceDef = t.Union[Source, _Source] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters