Skip to content

Commit ebf917e

Browse files
committed
Added abstract event class.
1 parent 36db063 commit ebf917e

File tree

7 files changed

+554
-13
lines changed

7 files changed

+554
-13
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ repos:
99
rev: v1.17.1
1010
hooks:
1111
- id: mypy
12+
additional_dependencies: [pydantic>=2.11.7, loguru>=0.7.3]
1213
- repo: local
1314
hooks:
1415
- id: pytest-coverage

eoapi_notifier/core/event.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Event.
3+
4+
Data object to hold information about notification events.
5+
"""
6+
7+
from datetime import UTC, datetime
8+
from typing import Any
9+
from uuid import uuid4
10+
11+
from pydantic import BaseModel, Field
12+
13+
14+
class NotificationEvent(BaseModel):
15+
"""
16+
Definition of a notification event and its content.
17+
18+
Attributes:
19+
id: Unique event identifier
20+
source: Event source (e.g., "/eoapi/stac/pgstac")
21+
type: Event type (e.g., "org.eoapi.stac.item")
22+
operation: Operation performed (INSERT, UPDATE, DELETE)
23+
collection: STAC collection ID
24+
item_id: STAC item ID
25+
timestamp: Event timestamp
26+
data: Additional event data
27+
"""
28+
29+
id: str = Field(default_factory=lambda: str(uuid4()))
30+
source: str
31+
type: str
32+
operation: str
33+
collection: str
34+
item_id: str | None = None
35+
timestamp: datetime = Field(default_factory=lambda: datetime.now(UTC))
36+
data: dict[str, Any] = Field(default_factory=dict)

eoapi_notifier/logging.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
"""Logging utilities for eoapi_notifier using loguru."""
22

33
import sys
4-
from typing import TYPE_CHECKING, Any
4+
from typing import Any
55

66
from loguru import logger
77

8-
if TYPE_CHECKING:
9-
from loguru._logger import Logger
10-
118

129
def setup_logging(
1310
level: str | int = "INFO",
1411
format_string: str | None = None,
1512
include_timestamp: bool = True,
1613
sink: Any | None = None,
17-
) -> "Logger":
14+
) -> Any:
1815
"""Set up logging for the eoapi_notifier package using loguru.
1916
2017
Args:
@@ -62,7 +59,7 @@ def setup_logging(
6259
return logger
6360

6461

65-
def get_logger(name: str | None = None) -> "Logger":
62+
def get_logger(name: str | None = None) -> Any:
6663
"""Get a logger instance for the eoapi_notifier package.
6764
6865
With loguru, there's typically one global logger instance,

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ authors = [
1212
]
1313
dependencies = [
1414
"loguru>=0.7.3",
15+
"pydantic>=2.11.7",
1516
]
1617
readme = "README.md"
1718
license = { text = "MIT" }
@@ -49,8 +50,6 @@ ignore = []
4950
[tool.ruff.format]
5051
quote-style = "double"
5152
indent-style = "space"
52-
skip-magic-trailing-comma = false
53-
line-ending = "auto"
5453

5554
[tool.mypy]
5655
python_version = "3.12"

0 commit comments

Comments
 (0)