1010from flask import Flask
1111
1212
13+ def get_env (name : str , default = None , required = False ):
14+ value = os .environ .get (name , default )
15+ if required and value is None :
16+ raise RuntimeError (f"Missing required environment variable: { name } " )
17+ return value
18+
19+
1320class Config :
1421 """Base configuration class for the Flask application."""
1522
16- SECRET_KEY = os .getenv ("SECRET_KEY" , "my_precious" )
17-
1823 # Celery configuration:
19- CELERY_BROKER_URL = os . getenv ("CELERY_BROKER_URL" )
20- CELERY_RESULT_BACKEND = os . getenv ("CELERY_RESULT_BACKEND" )
24+ CELERY_BROKER_URL = get_env ("CELERY_BROKER_URL" , required = False )
25+ CELERY_RESULT_BACKEND = get_env ("CELERY_RESULT_BACKEND" , required = False )
2126
22- # MinIO configuration:
23- MINIO_ENDPOINT = os .getenv ("MINIO_ENDPOINT" )
24- MINIO_ACCESS_KEY = os .getenv ("MINIO_ACCESS_KEY" )
25- MINIO_SECRET_KEY = os .getenv ("MINIO_SECRET_KEY" )
26- MINIO_BUCKET_NAME = os .getenv ("MINIO_BUCKET_NAME" , "bucket-name" )
27+ # rocrate validator configuration:
28+ PROFILES_PATH = get_env ("PROFILES_PATH" , required = False )
2729
2830
2931class DevelopmentConfig (Config ):
3032 """Development configuration class."""
31-
3233 DEBUG = True
33- ENV = "development"
3434
3535
3636class ProductionConfig (Config ):
3737 """Production configuration class."""
38-
3938 DEBUG = False
40- ENV = "production"
4139
4240
4341class InvalidAPIUsage (Exception ):
@@ -63,10 +61,13 @@ def make_celery(app: Flask = None) -> Celery:
6361 :param app: The Flask application to use.
6462 :return: The Celery instance.
6563 """
64+ env = os .environ .get ("FLASK_ENV" , "development" )
65+ config_cls = ProductionConfig if env == "production" else DevelopmentConfig
66+
6667 celery = Celery (
6768 app .import_name if app else __name__ ,
68- broker = os . getenv ( " CELERY_BROKER_URL" ) ,
69- backend = os . getenv ( " CELERY_RESULT_BACKEND" ) ,
69+ broker = config_cls . CELERY_BROKER_URL ,
70+ backend = config_cls . CELERY_RESULT_BACKEND ,
7071 )
7172
7273 if app :
0 commit comments