From cc3fb6e622a79587cc59269d00d6315a0407d448 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Mon, 11 Dec 2023 14:55:35 +0100 Subject: [PATCH] Moved code to plugins/enhancer folder --- amarillo/plugins/__init__.py | 1 + .../configuration.py} | 4 +- amarillo/plugins/{ => enhancer}/enhancer.py | 60 +++++++++++-------- 3 files changed, 38 insertions(+), 27 deletions(-) create mode 100644 amarillo/plugins/__init__.py rename amarillo/plugins/{enhancer_configuration.py => enhancer/configuration.py} (94%) rename amarillo/plugins/{ => enhancer}/enhancer.py (62%) diff --git a/amarillo/plugins/__init__.py b/amarillo/plugins/__init__.py new file mode 100644 index 0000000..0260537 --- /dev/null +++ b/amarillo/plugins/__init__.py @@ -0,0 +1 @@ +__path__ = __import__('pkgutil').extend_path(__path__, __name__) \ No newline at end of file diff --git a/amarillo/plugins/enhancer_configuration.py b/amarillo/plugins/enhancer/configuration.py similarity index 94% rename from amarillo/plugins/enhancer_configuration.py rename to amarillo/plugins/enhancer/configuration.py index 5a19df7..6e6760a 100644 --- a/amarillo/plugins/enhancer_configuration.py +++ b/amarillo/plugins/enhancer/configuration.py @@ -8,6 +8,7 @@ from amarillo.app.models.Carpool import Carpool from amarillo.app.services import stops from amarillo.app.services import trips from amarillo.app.services.carpools import CarpoolService +from amarillo.app.services import gtfs_generator from amarillo.app.configuration import configure_services @@ -48,4 +49,5 @@ def configure_enhancer_services(): container['carpools'].delete(carpool.agency, carpool.id) logger.info("Restored carpools: %s", container['carpools'].get_all_ids()) - logger.info("Starting scheduler") \ No newline at end of file + logger.info("Starting scheduler") + gtfs_generator.start_schedule() \ No newline at end of file diff --git a/amarillo/plugins/enhancer.py b/amarillo/plugins/enhancer/enhancer.py similarity index 62% rename from amarillo/plugins/enhancer.py rename to amarillo/plugins/enhancer/enhancer.py index 4f22248..c07a8b0 100644 --- a/amarillo/plugins/enhancer.py +++ b/amarillo/plugins/enhancer/enhancer.py @@ -1,11 +1,11 @@ import json -import time +from threading import Thread import logging import logging.config from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler -from enhancer_configuration import configure_enhancer_services +from amarillo.plugins.enhancer.configuration import configure_enhancer_services from amarillo.app.utils.container import container from amarillo.app.models.Carpool import Carpool from amarillo.app.utils.utils import agency_carpool_ids_from_filename @@ -13,13 +13,6 @@ from amarillo.app.utils.utils import agency_carpool_ids_from_filename logging.config.fileConfig('logging.conf', disable_existing_loggers=False) logger = logging.getLogger("enhancer") -logger.info("Hello Enhancer") - -configure_enhancer_services() - -observer = Observer() # Watch Manager - - class EventHandler(FileSystemEventHandler): # TODO FG HB should watch for both carpools and agencies # in data/agency, data/agencyconf, see AgencyConfService @@ -47,24 +40,39 @@ class EventHandler(FileSystemEventHandler): logger.exception("Eventhandler on_deleted encountered exception") -observer.schedule(EventHandler(), 'data/carpool', recursive=True) -observer.start() +def run_enhancer(): + logger.info("Hello Enhancer") -import time + configure_enhancer_services() -try: - # TODO FG Is this really needed? - cnt = 0 - ENHANCER_LOG_INTERVAL_IN_S = 600 - while True: - if cnt == ENHANCER_LOG_INTERVAL_IN_S: - logger.debug("Currently stored carpool ids: %s", container['carpools'].get_all_ids()) - cnt = 0 + observer = Observer() # Watch Manager - time.sleep(1) - cnt += 1 -finally: - observer.stop() - observer.join() + observer.schedule(EventHandler(), 'data/carpool', recursive=True) + observer.start() - logger.info("Goodbye Enhancer") + import time + + try: + # TODO FG Is this really needed? + cnt = 0 + ENHANCER_LOG_INTERVAL_IN_S = 600 + while True: + if cnt == ENHANCER_LOG_INTERVAL_IN_S: + logger.debug("Currently stored carpool ids: %s", container['carpools'].get_all_ids()) + cnt = 0 + + time.sleep(1) + cnt += 1 + finally: + observer.stop() + observer.join() + + logger.info("Goodbye Enhancer") + +def setup(app): + thread = Thread(target=run_enhancer) + thread.start() + + +if __name__ == "__main__": + run_enhancer() \ No newline at end of file