From 84342f29082b5de47cd2d95c168d2a8a96c1a68e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Gru=CC=88ndger?= Date: Sat, 30 May 2020 11:48:54 +0200 Subject: [PATCH] One configuration file is more clear --- app/config/__init__.py | 0 app/config/default.py | 27 ------------------------- app/config/test.py | 11 ----------- config.py | 45 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 38 deletions(-) delete mode 100644 app/config/__init__.py delete mode 100644 app/config/default.py delete mode 100644 app/config/test.py create mode 100644 config.py diff --git a/app/config/__init__.py b/app/config/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/config/default.py b/app/config/default.py deleted file mode 100644 index 9f7aecf..0000000 --- a/app/config/default.py +++ /dev/null @@ -1,27 +0,0 @@ -import os - -SECRET_KEY = "i-like-ogn" - -SQLALCHEMY_DATABASE_URI = os.environ.get("SQLALCHEMY_DATABASE_URI", "postgresql://postgres@localhost:5432/ogn") -SQLALCHEMY_TRACK_MODIFICATIONS = False - -# Flask-Cache stuff -CACHE_TYPE = "simple" -CACHE_DEFAULT_TIMEOUT = 300 - -# Celery stuff -CELERY_BROKER_URL = os.environ.get("CELERY_BROKER_URL", "redis://localhost:6379/0") -CELERY_RESULT_BACKEND = os.environ.get("CELERY_RESULT_BACKEND", "redis://localhost:6379/0") - -from celery.schedules import crontab -from datetime import timedelta - -CELERYBEAT_SCHEDULE = { - "update-ddb": {"task": "import_ddb", "schedule": timedelta(hours=1)}, - "update-country-codes": {"task": "update_receivers_country_code", "schedule": timedelta(days=1)}, - "update-takeoff-and-landing": {"task": "update_takeoff_landings", "schedule": timedelta(hours=1), "kwargs": {"last_minutes": 90}}, - "update-logbook": {"task": "update_logbook_entries", "schedule": timedelta(hours=2), "kwargs": {"day_offset": 0}}, - "update-max-altitudes": {"task": "update_logbook_max_altitude", "schedule": timedelta(hours=1), "kwargs": {"day_offset": 0}}, - "update-logbook-daily": {"task": "update_logbook_entries", "schedule": crontab(hour=1, minute=0), "kwargs": {"day_offset": -1}}, - "purge_old_data": {"task": "purge_old_data", "schedule": timedelta(hours=1), "kwargs": {"max_hours": 48}}, -} diff --git a/app/config/test.py b/app/config/test.py deleted file mode 100644 index 858c2fd..0000000 --- a/app/config/test.py +++ /dev/null @@ -1,11 +0,0 @@ -SQLALCHEMY_DATABASE_URI = "postgresql://postgres@localhost:5432/ogn_test" -SQLALCHEMY_TRACK_MODIFICATIONS = False -SQLALCHEMY_ECHO = True - -# Flask-Cache stuff -CACHE_TYPE = "simple" -CACHE_DEFAULT_TIMEOUT = 300 - -# Celery stuff -CELERY_BROKER_URL = "redis://localhost:6379/0" -CELERY_RESULT_BACKEND = "redis://localhost:6379/0" diff --git a/config.py b/config.py new file mode 100644 index 0000000..beaaa2b --- /dev/null +++ b/config.py @@ -0,0 +1,45 @@ +import os + +class BaseConfig: + SECRET_KEY = "i-like-ogn" + + # Flask-Cache stuff + CACHE_TYPE = "simple" + CACHE_DEFAULT_TIMEOUT = 300 + + # Redis stuff + REDIS_URL = "redis://localhost:6379/0" + + # Celery stuff + CELERY_BROKER_URL = os.environ.get("CELERY_BROKER_URL", REDIS_URL) + CELERY_RESULT_BACKEND = os.environ.get("CELERY_RESULT_BACKEND", REDIS_URL) + + +class DefaultConfig(BaseConfig): + SQLALCHEMY_DATABASE_URI = os.environ.get("SQLALCHEMY_DATABASE_URI", "postgresql://postgres:postgres@localhost:5432/ogn") + SQLALCHEMY_TRACK_MODIFICATIONS = False + + # Celery beat stuff + from celery.schedules import crontab + from datetime import timedelta + + beat_schedule = { + "transfer_beacons_to_database": {"task": "transfer_beacons_to_database", "schedule": timedelta(minutes=1)}, + "update-ddb": {"task": "import_ddb", "schedule": timedelta(hours=1)}, + "update-country-codes": {"task": "update_receivers_country_code", "schedule": timedelta(days=1)}, + "update-takeoff-and-landing": {"task": "update_takeoff_landings", "schedule": timedelta(hours=1), "kwargs": {"last_minutes": 90}}, + "update-logbook": {"task": "update_logbook_entries", "schedule": timedelta(hours=2), "kwargs": {"day_offset": 0}}, + "update-max-altitudes": {"task": "update_logbook_max_altitude", "schedule": timedelta(hours=1), "kwargs": {"day_offset": 0}}, + "update-logbook-daily": {"task": "update_logbook_entries", "schedule": crontab(hour=1, minute=0), "kwargs": {"day_offset": -1}}, + "purge_old_data": {"task": "purge_old_data", "schedule": timedelta(hours=1), "kwargs": {"max_hours": 48}}, + } + +class DevelopmentConfig(BaseConfig): + SQLALCHEMY_DATABASE_URI = "postgresql://postgres:postgres@localhost:5432/ogn_test" + SQLALCHEMY_TRACK_MODIFICATIONS = False + SQLALCHEMY_ECHO = True + +configs = { + 'default': DefaultConfig, + 'development': DevelopmentConfig +} \ No newline at end of file