-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Renamed trigger channel to event listener * Added sample event listener * Moved each event listener to its own dir
- Loading branch information
1 parent
9266c10
commit c672c5e
Showing
25 changed files
with
297 additions
and
153 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
try: | ||
from .commands import cli_start # ruff: noqa: F401 | ||
except ImportError: | ||
print("Failed to import commands.") | ||
from .commands import cli_start | ||
|
||
__all__ = ["cli_start"] |
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
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
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,17 @@ | ||
from .http.event_listener import HttpEventListener, HttpEventListenerSettings | ||
from .kafka.event_listener import KafkaEventListener, KafkaEventListenerSettings | ||
from .sample.event_listener import SampleEventListener, SampleEventListenerSettings | ||
|
||
EventListenerSettingsType = ( | ||
HttpEventListenerSettings | KafkaEventListenerSettings | SampleEventListenerSettings | ||
) | ||
|
||
__all__ = [ | ||
"EventListenerSettingsType", | ||
"HttpEventListener", | ||
"HttpEventListenerSettings", | ||
"KafkaEventListener", | ||
"KafkaEventListenerSettings", | ||
"SampleEventListener", | ||
"SampleEventListenerSettings", | ||
] |
15 changes: 12 additions & 3 deletions
15
port_ocean/core/trigger_channel/base.py → port_ocean/core/event_listener/base.py
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 |
---|---|---|
@@ -1,18 +1,27 @@ | ||
from abc import abstractmethod | ||
from typing import TypedDict, Callable, Any, Awaitable | ||
|
||
from pydantic import BaseSettings | ||
|
||
class TriggerChannelEvents(TypedDict): | ||
|
||
class EventListenerEvents(TypedDict): | ||
on_resync: Callable[[dict[Any, Any]], Awaitable[None]] | ||
|
||
|
||
class BaseTriggerChannel: | ||
class BaseEventListener: | ||
def __init__( | ||
self, | ||
events: TriggerChannelEvents, | ||
events: EventListenerEvents, | ||
): | ||
self.events = events | ||
|
||
@abstractmethod | ||
async def start(self) -> None: | ||
pass | ||
|
||
|
||
class EventListenerSettings(BaseSettings): | ||
type: str | ||
|
||
def to_request(self) -> dict[str, Any]: | ||
return {"type": self.type} |
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
File renamed without changes.
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,43 @@ | ||
from typing import Literal, Any | ||
|
||
from fastapi import APIRouter | ||
from loguru import logger | ||
from pydantic import AnyHttpUrl, Field | ||
|
||
from port_ocean.context.ocean import ocean | ||
from port_ocean.core.event_listener.base import ( | ||
BaseEventListener, | ||
EventListenerEvents, | ||
EventListenerSettings, | ||
) | ||
|
||
|
||
class HttpEventListenerSettings(EventListenerSettings): | ||
type: Literal["WEBHOOK"] | ||
app_host: AnyHttpUrl = Field(alias="appHost") | ||
|
||
def to_request(self) -> dict[str, Any]: | ||
return { | ||
**super().to_request(), | ||
"url": self.app_host + "/resync", | ||
} | ||
|
||
|
||
class HttpEventListener(BaseEventListener): | ||
def __init__( | ||
self, | ||
events: EventListenerEvents, | ||
event_listener_config: HttpEventListenerSettings, | ||
): | ||
super().__init__(events) | ||
self.event_listener_config = event_listener_config | ||
|
||
async def start(self) -> None: | ||
logger.info("Setting up HTTP Event Listener") | ||
target_channel_router = APIRouter() | ||
|
||
@target_channel_router.post("/resync") | ||
async def resync() -> None: | ||
await self.events["on_resync"]({}) | ||
|
||
ocean.app.fast_api_app.include_router(target_channel_router) |
Empty file.
Oops, something went wrong.