Skip to content

Commit cc2189d

Browse files
committed
chore: refactor task builder, better naming and documentation
1 parent 22283b5 commit cc2189d

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

app/api/hooks/metadata.py

Lines changed: 2 additions & 2 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 TKB
10+
from app.task_builder import build_task
1111

1212
logger = logging.getLogger(__name__)
1313

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

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

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 TKB
11+
from .task_builder import build_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 TKB(command).execute()
93+
await build_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/task_builder.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
1-
import asyncio
1+
"""RSX-11M for life"""
22

3-
from app.runner import Task
3+
from asyncio import create_subprocess_shell, subprocess
44

5+
from app.runner import Task
56

6-
def TKB(command: str) -> Task:
7-
"""Task Builder for running subprocesses asynchronously. The name is a reference to RSX-11M+ :)
87

9-
This function takes a command string, splits it into arguments, and creates a Task
10-
that can be executed asynchronously. It uses asyncio's subprocess capabilities to
11-
run the command in a subprocess, capturing both stdout and stderr.
8+
def build_task(shell_command: str) -> Task:
9+
"""Creates a Task to run a shell command asynchronously.
1210
1311
Args:
14-
command (str): The shell command to run.
15-
12+
shell_command (str): The shell command to run.
1613
"""
17-
return Task(
18-
asyncio.create_subprocess_shell(
19-
command,
20-
stdout=asyncio.subprocess.PIPE,
21-
stderr=asyncio.subprocess.PIPE,
22-
)
23-
)
14+
return Task(create_subprocess_shell(shell_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE))

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 TKB
3+
from app.task_builder import build_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 TKB(f"rm {test_path}").execute()
12+
await build_task(f"rm {test_path}").execute()
1313

1414
assert not test_path.exists()

0 commit comments

Comments
 (0)