Skip to content

Commit

Permalink
Named
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith committed Nov 27, 2024
1 parent c7d6f57 commit acf8746
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
12 changes: 2 additions & 10 deletions src/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,10 @@
T = TypeVar("T")


class JobProtocol(Protocol):
"""Represent a Job class from src/job.py."""
class Named(Protocol):
"""Represents any class with name field."""

name: str
source: Any
destination: Any

async def run(self) -> None:
"""Represent the run method of the Job class."""

def __str__(self) -> str:
"""Represent the __str__ method of the Job class."""


class Validate(ABC):
Expand Down
4 changes: 2 additions & 2 deletions src/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from enum import Enum
from typing import Any

from src.interfaces import Destination, Source
from src.interfaces import Destination, Named, Source
from src.logger import log
from src.metrics import collect_metrics

Expand Down Expand Up @@ -45,7 +45,7 @@ def from_string(cls, value: str) -> Database:


@dataclass
class Job:
class Job(Named):
"""Base class for all data synchronization jobs.
A job represents a single data transfer operation from a source
Expand Down
4 changes: 2 additions & 2 deletions src/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from prometheus_client import CollectorRegistry, Counter, Gauge, push_to_gateway

from src.interfaces import JobProtocol
from src.interfaces import Named
from src.logger import log


Expand Down Expand Up @@ -52,7 +52,7 @@ def collect_metrics(

@wraps(func)
async def wrapper(
self: JobProtocol, *args: Iterable[Any], **kwargs: Mapping[Any, Any]
self: Named, *args: Iterable[Any], **kwargs: Mapping[Any, Any]
) -> Any:
if not (prometheus_url := env("PROMETHEUS_PUSHGATEWAY_URL")):
return await func(self, *args, **kwargs)
Expand Down

0 comments on commit acf8746

Please sign in to comment.