refactor: add strategy.process() to BaseStrategy

This commit is contained in:
Felix Spöttel
2023-06-29 16:31:57 +02:00
parent 05ebc17215
commit 85c3f1fc44
3 changed files with 25 additions and 25 deletions

View File

@@ -17,6 +17,20 @@ class TaskProtocol(Protocol):
class BaseStrategy(ABC):
def process(self, job: models.Job) -> TaskReturnValue:
if job.type == models.JobType.transcript:
return self.transcribe(job)
elif job.type == models.JobType.translation:
return self.translate(job)
else:
return self.detect_language(job)
def cleanup(self, job_id: UUID) -> None:
try:
os.remove(self._get_tmp_file(job_id))
except OSError:
...
def transcribe(self, job: models.Job) -> TaskReturnValue:
raise NotImplementedError()
@@ -26,12 +40,6 @@ class BaseStrategy(ABC):
def detect_language(self, job: models.Job) -> TaskReturnValue:
raise NotImplementedError()
def cleanup(self, job_id: UUID) -> None:
try:
os.remove(self._get_tmp_file(job_id))
except OSError:
pass
def _get_tmp_file(self, job_id: UUID) -> str:
tmp = tempfile.gettempdir()
return os.path.join(tmp, str(job_id))