Skip to content

Commit 9c31349

Browse files
committed
refactor: task builder has become redundant
task creation has been simplified to the point where a factory was pointless
1 parent cc2189d commit 9c31349

File tree

5 files changed

+13
-27
lines changed

5 files changed

+13
-27
lines changed

app/api/hooks/metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from app.api.hooks.schema.request import HookRequest
99
from app.media.ffprobe_schema import FfprobeOutput
10-
from app.task_builder import build_task
10+
from app.runner import Task
1111

1212
logger = logging.getLogger(__name__)
1313

@@ -33,8 +33,8 @@ class MetadataExtractor:
3333
"""Class to handle metadata extraction and compliance checking."""
3434

3535
async def _run_ffprobe(self, filepath: Path) -> str:
36-
stdout, _ = await build_task(
37-
f"ffprobe -v quiet -show_format -show_streams -of json {shlex.quote(str(filepath))}"
36+
stdout, _ = await Task(
37+
f"ffprobe -v quiet -show_format -show_streams -of json {shlex.quote(str(filepath))}",
3838
).execute()
3939
return stdout
4040

app/ingest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .archive_store import Archive
99
from .media.comand_template import ProfileTemplateArguments, TemplatedCommandGenerator
1010
from .media.ffprobe_schema import FfprobeOutput
11-
from .task_builder import build_task
11+
from .runner import Task
1212

1313
DESIRED_FORMATS = (
1414
FormatEnum.LARGE_THUMB,
@@ -90,7 +90,7 @@ async def _process_format(
9090
command = template.render(template_args)
9191
self.logger.debug("Generated command: %s", command)
9292

93-
await build_task(command).execute()
93+
await Task(command).execute()
9494

9595
self.logger.info("Creating video file entry for %s", output_file)
9696
await self.django_api.create_video_file(filename=str(output_file), file_format=file_format, video_id=video_id)

app/runner.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import logging
2-
from asyncio.subprocess import Process
3-
from collections.abc import Coroutine
4-
from typing import Any
2+
from asyncio import subprocess
53

64
logger = logging.getLogger(__name__)
75

@@ -11,10 +9,12 @@ class Task:
119
Raises ChildProcessError if the command fails.
1210
"""
1311

14-
proc: Coroutine[Any, Any, Process]
12+
command_line: str
1513

16-
def __init__(self, proc: Coroutine[Any, Any, Process]):
17-
self.proc = proc
14+
def __init__(self, command_line: str):
15+
self.command_line = command_line
16+
self.proc = subprocess.create_subprocess_shell(command_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
17+
logger.debug("Created task for command: %s", command_line)
1818

1919
async def execute(self) -> tuple[str, str]:
2020
proc = await self.proc

app/task_builder.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/test_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from app.task_builder import build_task
3+
from app.runner import Task
44

55

66
@pytest.mark.asyncio
@@ -9,6 +9,6 @@ async def test_basic_run(tmp_path):
99
test_path.touch()
1010
assert test_path.exists()
1111

12-
await build_task(f"rm {test_path}").execute()
12+
await Task(f"rm {test_path}").execute()
1313

1414
assert not test_path.exists()

0 commit comments

Comments
 (0)