Beispiel #1
0
 def _store_results_in_db(self, metric_values: List[MetricValue], feature_dto, feature_meta):
     start_time = datetime.utcnow()
     for metric_value in metric_values:
         self.metric_definition_repo.get_or_create(metric_value.definition)
         self.metric_value_repo.insert(metric_value)
     self.feature_meta_repo.insert(feature_meta)
     if read_env_var("EXTRACTION_FULL_RESULT_PERSISTENCE", int, 1):
         try:
             self.feature_data_repo.insert(feature_dto)
         except DatabaseError as e:
             self.logger.error(
                 "Couldn't insert feature of size {} from into DB: {}".format(feature_dto.size_humanized(), e))
             raise e
     else:
         self.logger.warning("Ignoring full result due to EXTRACTION_FULL_RESULT_PERSISTENCE setting!")
     return seconds_between(start_time)
Beispiel #2
0
from audiopyle.lib.utils.logger import setup_logger, get_logger
from audiopyle.api.audio_file import AudioFileListApi, AudioFileDetailApi
from audiopyle.api.audio_tag import AudioTagApi
from audiopyle.api.automation import AutomationApi
from audiopyle.api.config import PluginConfigListApi, MetricConfigListApi, PluginConfigApi, MetricByNameApi, \
    MetricsByPluginApi
from audiopyle.api.metric import MetricDefinitionListApi, MetricDefinitionDetailsApi, MetricValueListApi, \
    MetricValueDetailsApi
from audiopyle.api.plugin import PluginListApi, PluginDetailApi
from audiopyle.api.root import CoordinatorApi
from audiopyle.api.result import ResultDataApi, ResultMetaApi, ResultStatsApi
from audiopyle.api.request import RequestListApi, RequestDetailsApi, RequestStatusApi

app = Flask(__name__)

allowed_origins = read_env_var("API_ALLOWED_ORIGIN", str, "http://localhost:8008,http://ui.local:8080").split(",")
cors = CORS(app, origins=allowed_origins, methods=["GET", "POST", "DELETE", "PUT"])


def main():
    setup_logger()
    logger = get_logger()
    logger.info("Initializing Coordinator app...")
    create_db_tables(only_if_absent=True)
    start_app(logger, "0.0.0.0", 8080)


def start_app(logger: Logger, host: str, port: int):
    audio_file_store = Mp3FileStore(AUDIO_FILES_DIR)
    config_json_store = JsonFileStore(CONFIG_DIR)
    plugin_config_provider = PluginConfigProvider(config_json_store, logger)
Beispiel #3
0
from audiopyle.lib.utils.env_var import read_env_var

broker_url = 'pyamqp://*****:*****@{}//'.format(
    read_env_var("RABBITMQ_SERIVCE_HOST", str))
result_backend = 'db+mysql://audiopyle:audiopyle@{}:{}/audiopyle'.format(
    read_env_var("MYSQL_SERVICE_HOST", str),
    read_env_var("MYSQL_SERVICE_PORT", int))

task_serializer = 'json'
result_serializer = 'json'
accept_content = ['json']
timezone = 'Europe/Warsaw'
enable_utc = True

worker_concurrency = read_env_var(
    "EXTRACTION_CONCURRENCY", int,
    default=2)  # concurrent tasks at a time per worker
task_acks_late = True

broker_pool_limit = read_env_var("EXTRACTION_BROKER_CONN_POOL_SIZE",
                                 int,
                                 default=4)

worker_prefetch_multiplier = 1
worker_max_tasks_per_child = 1
worker_max_memory_per_child = read_env_var(
    "EXTRACTION_MEMORY_LIMIT_MB", int, default=256) * 1000
worker_send_task_events = True
task_send_sent_event = True
task_track_started = True
task_soft_time_limit = read_env_var(
Beispiel #4
0
def get_ui_port():
    return read_env_var("UI_SERVICE_PORT", int, default=8008)
Beispiel #5
0
def get_ui_host():
    return read_env_var("UI_SERVICE_HOST", str, default="localhost")
Beispiel #6
0
def get_api_port():
    return read_env_var("API_SERVICE_PORT", int, default=8080)
Beispiel #7
0
 def test_should_read_existing_variable(self):
     home_value = read_env_var("HOME", str)
     assert_that(home_value).is_not_empty().starts_with("/")
Beispiel #8
0
 def test_should_fallback_to_default_on_non_wrong_variable_type(self):
     default_value = 1.1
     wrong_type_variable = read_env_var("HOME", float, default_value)
     assert_that(wrong_type_variable).is_equal_to(default_value)
Beispiel #9
0
 def test_should_fallback_to_default_on_non_existing_variable(self):
     default_value = "some_default"
     non_existing_value = read_env_var("NON_EXSTING_VARIABLE", str, default_value)
     assert_that(non_existing_value).is_equal_to(default_value)
Beispiel #10
0
def _build_mysql_conn_string(host: str = None, port: int = None) -> str:
    return "mysql://*****:*****@{}:{}/audiopyle".format(
        host or read_env_var("MYSQL_SERVICE_HOST", str, "localhost"), port
        or read_env_var("MYSQL_SERVICE_PORT", int, 3306))