-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor EventsRouter bettween sync and async router
- Loading branch information
Showing
8 changed files
with
540 additions
and
125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
Generic async router to send events to hosts via celery. | ||
""" | ||
from event_routing_backends.tasks import dispatch_bulk_events, dispatch_event, dispatch_event_persistent | ||
from event_routing_backends.backends.events_router import EventsRouter | ||
|
||
class AsyncEventsRouter(EventsRouter): | ||
""" | ||
Router to send events to hosts via celery using requests library. | ||
""" | ||
|
||
def dispatch_event(self, event_name, event, router_type, host_configurations): | ||
""" | ||
Dispatch the event to the configured router. | ||
Arguments: | ||
event_name (str): name of the original event. | ||
updated_event (dict): processed event dictionary | ||
router_type (str): type of the router | ||
host_configurations (dict): host configurations dict | ||
""" | ||
dispatch_event.delay(event_name, event, router_type, host_configurations) | ||
|
||
def dispatch_bulk_events(self, events, router_type, host_configurations): | ||
""" | ||
Dispatch the a list of events to the configured router in bulk. | ||
Arguments: | ||
events (list[dict]): list of processed event dictionaries | ||
router_type (str): type of the router | ||
host_configurations (dict): host configurations dict | ||
""" | ||
dispatch_bulk_events.delay(events, router_type, host_configurations) | ||
|
||
def dispatch_event_persistent(self, event_name, event, router_type, host_configurations): | ||
""" | ||
Dispatch the event to the configured router providing persistent storage. | ||
Arguments: | ||
event_name (str): name of the original event. | ||
updated_event (dict): processed event dictionary | ||
router_type (str): type of the router | ||
host_configurations (dict): host configurations dict | ||
""" | ||
dispatch_event_persistent.delay(event_name, event, router_type, host_configurations) |
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,45 @@ | ||
""" | ||
Generic router to send events to hosts. | ||
""" | ||
from event_routing_backends.tasks import send_event, bulk_send_events | ||
from event_routing_backends.backends.events_router import EventsRouter | ||
|
||
class SyncEventsRouter(EventsRouter): | ||
""" | ||
Router to send events to hosts via celery using requests library. | ||
""" | ||
|
||
def dispatch_event(self, event_name, event, router_type, host_configurations): | ||
""" | ||
Dispatch the event to the configured router. | ||
Arguments: | ||
event_name (str): name of the original event. | ||
updated_event (dict): processed event dictionary | ||
router_type (str): type of the router | ||
host_configurations (dict): host configurations dict | ||
""" | ||
send_event(None, event_name, event, router_type, host_configurations) | ||
|
||
def dispatch_bulk_events(self, events, router_type, host_configurations): | ||
""" | ||
Dispatch the a list of events to the configured router in bulk. | ||
Arguments: | ||
events (list[dict]): list of processed event dictionaries | ||
router_type (str): type of the router | ||
host_configurations (dict): host configurations dict | ||
""" | ||
bulk_send_events(None, events, router_type, host_configurations) | ||
|
||
def dispatch_event_persistent(self, event_name, event, router_type, host_configurations): | ||
""" | ||
Dispatch the event to the configured router providing persistent storage. | ||
Arguments: | ||
event_name (str): name of the original event. | ||
updated_event (dict): processed event dictionary | ||
router_type (str): type of the router | ||
host_configurations (dict): host configurations dict | ||
""" | ||
self.dispatch_event(event_name, event, router_type, host_configurations) | ||
Oops, something went wrong.