import json import logging import os from sqlalchemy.pool import NullPool from sqlalchemy.pool import StaticPool # Application info APP_NAME = 'daemon-youtube-ownership' APP_VERSION = '0.0.1' # Environments ENVIRONMENT_PROD = 'prod' ENVIRONMENT_DEV = 'dev' ENVIRONMENT_QA = 'qa' ENVIRONMENT_TEST = 'test' ENVIRONMENT = os.environ.get('Environment', ENVIRONMENT_DEV) if ENVIRONMENT == ENVIRONMENT_DEV: from dotenv import load_dotenv # Load environment variables from a .env file load_dotenv('./.env') # Amazon Web Services # ------------------- AWS_REGION = os.environ.get('AWS_REGION', 'us-east-1') # Queue configuration # ------------------- # All queues are prefixed with the environment name (for policy settings) and # the name of the service (which allows to quickly identify unused pidbox). YOUTUBE_SQS_QUEUE = '{}-yt-ownership-1'.format(ENVIRONMENT) SQS_MESSAGE_RETENTION_PERIOD = 1200 SQS_WAIT_TIME_SECONDS = 20 SQS_MESSAGE_VISIBILITY_TIMEOUT = 60 # Database # -------- # Connection string DB_CONNECTION_STRING = os.environ.get('DB_CONNECTION_STRING') DB_POOLCLASS = NullPool # Google API integration # ---------------------- # Convert string key into json file on disk for the service account GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY') GOOGLE_API_KEY_FILE = '{}_google_api_key.json'.format(ENVIRONMENT) try: json_data = json.loads(GOOGLE_API_KEY, strict=False) with open(GOOGLE_API_KEY_FILE, 'w') as f: json.dump(json_data, f, ensure_ascii=False, indent=4) except Exception as e: raise e # Logging # ------- # Sentry: allows us to track effectively exceptions. SENTRY_DSN = os.environ.get('SENTRY_DSN') # Loggly LOGGER_LEVEL = getattr(logging, os.environ.get('LOGGER_LEVEL', 'INFO')) LOGGER_NAME = 'ows1' # Application settings # -------------------- # Number of worker threads for picking the messages from SQS and making YouTube # API requests QUEUE_READER_THREADS = int(os.environ.get('QUEUE_READER_THREADS', 1)) API_EXECUTOR_THREADS = int(os.environ.get('API_EXECUTOR_THREADS', 6)) # Number of messages to be prefetched from SQS into internal Queue PREFETCH_COUNT = API_EXECUTOR_THREADS # Number of messages to pull from SQS (max 10) SQS_NUM_MESSAGES = PREFETCH_COUNT if PREFETCH_COUNT <= 10 else 10 STOP_TIMEOUT = 100 DEBUG = int(os.environ.get('DEBUG', 0)) # Track success Api call attempts # ------------------------------- # By default, only failures during the YouTube API calls are being saved to RDS # database. You can enable the setting below in order to save the successes # also. TRACK_SUCCESSFUL_API_CALLS = int(os.environ.get('TRACK_SUCCESSES', 0)) # Retry count API_RETRY_COUNT = 3 # Retry timeout API_RETRY_TIMEOUT = 1 # Use progressive retry timeout API_RETRY_PROGRESSIVE_TIMEOUT = True # Rate limit for API requests per second API_RATE_LIMIT = int(os.environ.get('API_RATE_LIMIT', 2)) # Test assets # ----------- # For test, dev and QA environments we restrict access to Content ID API # with hard-coded list of asset ISRCs. This will prevent accidental # changes to real live data. RESTRICT_API_ACCESS = True TEST_ISRCS = ['US26V4410006', 'US26V4410007', 'US26V4410008', 'US26V4410009', 'US26V4410010', 'US26V4410011', 'US26V4410012'] # Override default config settings for particular environments # ------------------------------------------------------------ # Dev if ENVIRONMENT == ENVIRONMENT_DEV: DEBUG = 1 TRACK_SUCCESSFUL_API_CALLS = 1 # Prod if ENVIRONMENT == ENVIRONMENT_PROD: assert SENTRY_DSN, 'SENTRY_DSN env variable required in prod environment' assert DB_CONNECTION_STRING, 'DB_CONNECTION_STRING is missing from the ' \ 'environment' RESTRICT_API_ACCESS = False # Test if ENVIRONMENT == ENVIRONMENT_TEST: DB_CONNECTION_STRING = 'sqlite://' DB_POOLCLASS = StaticPool