refactor(analyzer): improve analyzer pipeline module (#1542)

* rename steps to pipeline module

* move pipeline entrypoint to pipeline module

* rename steps test module to pipeline

* fix paths after renames

* move step protocol to pipeline

* create pipeline status enum

* use Protocol from typing extensions

* Fix linting
This commit is contained in:
Jonas L 2022-01-28 06:09:19 +01:00 committed by GitHub
parent 74c8d20284
commit cba905e367
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 34 additions and 26 deletions

View file

@ -8,7 +8,7 @@ import pika
from libretime_shared.config import RabbitMQConfig
from loguru import logger
from .pipeline import Pipeline
from .pipeline import Pipeline, PipelineStatus
from .status_reporter import StatusReporter
EXCHANGE = "airtime-uploads"
@ -265,7 +265,7 @@ class MessageListener:
metadata = q.get()
except Exception as e:
logger.error("Analyzer pipeline exception: %s" % str(e))
metadata["import_status"] = Pipeline.IMPORT_STATUS_FAILED
metadata["import_status"] = PipelineStatus.failed
# Ensure our queue doesn't fill up and block due to unexpected behaviour. Defensive code.
while not q.empty():

View file

@ -0,0 +1 @@
from .pipeline import Pipeline, PipelineStatus

View file

@ -1,14 +1,29 @@
""" Analyzes and imports an audio file into the Airtime library.
"""
from enum import Enum
from queue import Queue
from typing import Any, Dict
from loguru import logger
from typing_extensions import Protocol
from .steps.analyze_cuepoint import analyze_cuepoint
from .steps.analyze_metadata import analyze_metadata
from .steps.analyze_playability import UnplayableFileError, analyze_playability
from .steps.analyze_replaygain import analyze_replaygain
from .steps.organise_file import organise_file
from .analyze_cuepoint import analyze_cuepoint
from .analyze_metadata import analyze_metadata
from .analyze_playability import UnplayableFileError, analyze_playability
from .analyze_replaygain import analyze_replaygain
from .organise_file import organise_file
class Step(Protocol):
@staticmethod
def __call__(filename: str, metadata: Dict[str, Any]):
...
class PipelineStatus(int, Enum):
succeed = 0
pending = 1
failed = 2
class Pipeline:
@ -21,8 +36,6 @@ class Pipeline:
the failure to import can be reported back to the web application.
"""
IMPORT_STATUS_FAILED = 2
@staticmethod
def run_analysis(
queue,
@ -99,7 +112,7 @@ class Pipeline:
queue.put(metadata)
except UnplayableFileError as e:
logger.exception(e)
metadata["import_status"] = Pipeline.IMPORT_STATUS_FAILED
metadata["import_status"] = PipelineStatus.failed
metadata["reason"] = "The file could not be played."
raise e
except Exception as e:

View file

@ -1,7 +0,0 @@
from typing import Any, Dict, Protocol
class Step(Protocol):
@staticmethod
def __call__(filename: str, metadata: Dict[str, Any]):
...