diff --git a/event_routing_backends/handlers.py b/event_routing_backends/handlers.py index dacf63f3..4bbd11ef 100644 --- a/event_routing_backends/handlers.py +++ b/event_routing_backends/handlers.py @@ -3,6 +3,9 @@ """ import json import logging +import sched +import time +import sys from django.dispatch import receiver from eventtracking.backends.event_bus import EventBusRoutingBackend @@ -12,6 +15,11 @@ logger = logging.getLogger(__name__) +scheduler = sched.scheduler(time.time, time.sleep) + + +def send_batch(): + print("Sending events in batch") @receiver(TRACKING_LOG_EVENT_EMITTED) def send_tracking_log_to_backends( @@ -55,3 +63,15 @@ def send_tracking_log_to_backends( engine.send_to_backends(processed_event.copy()) except EventEmissionExit: logger.info("[EventEmissionExit] skipping event {}".format(event["name"])) + + + +def repeat_task(): + print("Repeat task") + scheduler.enter(5, 1, send_batch) + scheduler.enter(5, 1, repeat_task, ()) + + +if "consume_events" in sys.argv: + repeat_task() + scheduler.run()