Skip to content

Commit

Permalink
feat(render): Add logging for new render job
Browse files Browse the repository at this point in the history
This commit adds logging functionality to the render_replay function in the `render.py` file. Now, when a new render job is started, a log message will be generated with details such as the Job ID, Replay ID (if available), and Filename. This helps in tracking and monitoring render jobs.

Additionally, the commit also updates the filepath generation logic to use the newly generated Job ID instead of generating a random filename each time. This improves consistency and makes it easier to identify rendered files.

The rendering process has also been updated to include quality settings (quality=9) and frame rate settings (fps=30) for better output results.

Closes #123
  • Loading branch information
SakuraIsayeki committed Jul 21, 2023
1 parent 192acb1 commit 52ded6b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions wowskarma_api_minimap/src/routes/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import os

import pathlib
from asyncio.log import logger

from fastapi import APIRouter, HTTPException, status, UploadFile, BackgroundTasks
from fastapi.responses import FileResponse
from renderer.data import ReplayData
Expand Down Expand Up @@ -40,25 +42,29 @@ async def render_replay(
detail="File is too large"
)

# We're gonna write the replay data to a temporary file, in the following folder:
# /tmp/wows-karma/minimap/
# Log the new job.
job_id = binascii.b2a_hex(os.urandom(7))
logger.info(f"Started new render job: Job ID: {job_id}, Replay ID: {replay_id or 'None'}, "
f"Filename: {file.filename}.")

# Ensure the folder exists, if not, create it.
# Ensure the work folder exists, if not, create it.
os.makedirs(settings.replay.temp_workdir, exist_ok=True)

# Render time!
replay_info = ReplayParser(file.file, True).get_info()
replay_data: ReplayData = replay_info["hidden"]["replay_data"]

# Concat filepaths to get the full path to the replay file.
filepath = pathlib.Path(settings.replay.temp_workdir, f"{binascii.b2a_hex(os.urandom(7))}.mp4")


filepath = pathlib.Path(settings.replay.temp_workdir, f"{job_id}.mp4")
renderer = Renderer(
replay_data,
enable_chat=True,
team_tracers=True,
target_player_id=target_player_id
)
renderer.start(str(filepath))
renderer.start(str(filepath), quality=9, fps=30)

background_tasks.add_task(os.remove, filepath)
return FileResponse(filepath, media_type="video/mp4", filename=f"{replay_id or 'replay'}.mp4")

0 comments on commit 52ded6b

Please sign in to comment.