"""This file contains configuration data for python daemon and workers.""" import logging import os import sentry_sdk from sentry_sdk.integrations.logging import LoggingIntegration # Application info APP_NAME = 'daemon-transcoding' 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) # Amazon Web Services # ------------------- # 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). SQS_TRANSCODING_URL = os.environ.get('SQS_TRANSCODING_URL') SQS_WAIT_TIME_SECONDS = int(os.environ.get('SQS_WAIT_TIME_SECONDS', 10)) SQS_MESSAGE_VISIBILITY_TIMEOUT = int(os.environ.get( 'SQS_MESSAGE_VISIBILITY_TIMEOUT', 60)) SQS_NUM_MESSAGES_TO_PROCESS = int(os.environ.get( 'SQS_NUM_MESSAGES_TO_PROCESS', 10)) # Url endpoints configuration OWS_TRANSCODING_SERVICE_NAME = 'ows-transcoding' POST_JOB_STATUS_PATH_TEMPLATE = '/transcoding-job/{transcoding_job_id}/status' OWS_RETRIES = int(os.environ.get('OWS_RETRIES', 3)) OWS_TIMEOUT = int(os.environ.get('OWS_TIMEOUT', 30)) # Logging # ------- # Fluentd LOGGER_LEVEL = getattr(logging, os.environ.get('LOGGER_LEVEL', 'INFO')) LOGGER_NAME = 'ows1' # Sentry: allows us to track effectively exceptions. SENTRY_DSN = os.environ.get('SENTRY_DSN') sentry_logging = LoggingIntegration( level=LOGGER_LEVEL, event_level=None # Don't send error log as sentry event. ) sentry_sdk.init( dsn=SENTRY_DSN, environment=ENVIRONMENT, integrations=[sentry_logging] ) # Application settings # -------------------- # Number of worker threads for picking the messages from SQS # and executing the PDF generation QUEUE_READER_THREADS = int(os.environ.get('QUEUE_READER_THREADS', 1)) API_EXECUTOR_THREADS = int(os.environ.get('API_EXECUTOR_THREADS', 1)) # Number of messages to be prefetched from SQS into internal Queue PREFETCH_COUNT = API_EXECUTOR_THREADS STOP_TIMEOUT = 100 DEBUG = int(os.environ.get('DEBUG', 0)) # Output directory configuration. TMP_DIRECTORY_PATH = os.environ.get('TMP_DIRECTORY_PATH', '/tmp') # leave formatted worker_id WORKER_TMP_DIRECTORY_PATH = ( '{tmp_root}/worker_{worker_id}'.format( tmp_root=TMP_DIRECTORY_PATH, worker_id='{worker_id}')) # FFMPEG configuration. DEFAULT_FFMPEG_PATH = 'ffmpeg' FFMPEG_PATH = os.environ.get('FFMPEG_PATH', DEFAULT_FFMPEG_PATH) FFMPEG_INPUT_OPTIONS = ' '.join(( '-rw_timeout 15000000', # Maximum time to wait for (network) read/write operations to complete, in microseconds. '-reconnect 1', # Reconnect automatically when disconnected before EOF is hit. '-reconnect_on_network_error 1', # Reconnect automatically in case of TCP/TLS errors during connect. '-reconnect_on_http_error 500,502,503,504', '-reconnect_max_retries 6', # Set the maximum number of times to retry a connection. )) # Override default config settings for particular environments # ------------------------------------------------------------ # Dev if ENVIRONMENT == ENVIRONMENT_DEV: DEBUG = 1 # Prod and QA if ENVIRONMENT in (ENVIRONMENT_QA, ENVIRONMENT_PROD): assert SENTRY_DSN, 'SENTRY_DSN env variable required in prod environment' DEFAULT_MEDIAINFO_PATH = 'mediainfo' MEDIAINFO_PATH = os.environ.get('MEDIAINFO_PATH', DEFAULT_MEDIAINFO_PATH) S3_UPLOAD_CHUNK_SIZE = int(os.environ.get('S3_UPLOAD_CHUNK_SIZE', 67108864))