Skip to content

Commit

Permalink
fix(settings): Settings priority issues
Browse files Browse the repository at this point in the history
Some settings had incorrect keys and were pulling defaults from the
pydantic defaults. I removed the defaults from Pydantic for better
config/code seperation.

Some settings were renamed to more accurately reflect their purpose,
leading to some breaking changes in configuration. Unfortunately, if a
user attempted to change the settings with incorrect keys,
they were ineffective anyway.

Although technically a breaking change, will treat this as semver minor
bump. The version constraints are still set to respect semver minor
changes as incompatible.
  • Loading branch information
in03 committed Feb 20, 2023
1 parent e92b4a9 commit b11c5de
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/proxima/celery/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

# Remap terms
broker_settings = {
"broker_url": settings.broker.broker_url,
"result_backend": settings.broker.broker_url,
"broker_url": settings.broker.url,
"result_backend": settings.broker.url,
"result_expires": settings.broker.result_expires,
}

Expand Down
2 changes: 1 addition & 1 deletion src/proxima/celery/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def encode_proxy(self, job_dict: dict) -> str:
raise Reject(e, requeue=False)

# Create logfile
encode_log_dir = job.settings.paths.ffmpeg_logfile
encode_log_dir = job.settings.paths.ffmpeg_logfile_dir
os.makedirs(encode_log_dir, exist_ok=True)
logfile_path = os.path.normpath(
os.path.join(encode_log_dir, job.output_file_name + ".txt")
Expand Down
61 changes: 27 additions & 34 deletions src/proxima/settings/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from pydantic import (
BaseModel,
BaseSettings,
DirectoryPath,
Field,
RedisDsn,
ValidationError,
validator,
)
from pydantic.env_settings import SettingsSourceCallable
from rich import print
from rich.panel import Panel

Expand Down Expand Up @@ -54,17 +54,13 @@ def must_be_valid_loglevel(cls, v):


class Paths(BaseModel):
proxy_root: DirectoryPath = Field(
"R:/@ProxyMedia", description="Root directory for proxy transcode structure"
)
ffmpeg_logfile: DirectoryPath = Field(
"R:/ProxyMedia/@logs", description="Path for ffmpeg logfiles"
)
linkable_proxy_suffix_regex: list[str] = Field(
"[-\\d, _\\d, S\\d*]", min_items=1, unique_items=True
proxy_root: str = Field(
..., description="Root directory for proxy transcode structure"
)
ffmpeg_logfile_dir: str = Field(..., description="Path for ffmpeg logfiles")
linkable_proxy_suffix_regex: list[str] = Field(..., min_items=1, unique_items=True)

@validator("proxy_root", "ffmpeg_logfile")
@validator("proxy_root", "ffmpeg_logfile_dir")
def check_path_exists(cls, v):
if not os.path.exists(v):
raise ValueError(f"Path {v} does not exist")
Expand All @@ -81,50 +77,46 @@ def must_be_valid_regex(cls, v):

class Proxy(BaseModel):
ffmpeg_loglevel: str = Field(
"error", description="Ffmpeg's internal loglevel visible in worker output"
..., description="Ffmpeg's internal loglevel visible in worker output"
)
preset_nickname: str = Field(
"ProRes 422 720P", description="Encoding preset nickname for easy reference"
)
codec: str = Field(
"prores", description="Ffmpeg supported codec for proxy transcoding"
nickname: str = Field(
..., description="Encoding preset nickname for easy reference"
)
codec: str = Field(..., description="Ffmpeg supported codec for proxy transcoding")
vertical_res: str = Field(
"720",
...,
description="Target vertical resolution in pixels (aspect ratio is automatically preserved)",
)
profile: str = Field("0", description="Ffmpeg profile for given codec")
pix_fmt: str = Field("yuv422p", description="Ffmpeg pixel format for given codec")
profile: str = Field(..., description="Ffmpeg profile for given codec")
pix_fmt: str = Field(..., description="Ffmpeg pixel format for given codec")
audio_codec: str = Field(
"pcm_s16le",
...,
description="Ffmpeg supported audio codec for given format/container",
)
audio_samplerate: str = Field(
"audio_samplerate",
...,
description="Ffmpeg supported audio samplerate for audio codec",
)
misc_args: list[str] = Field(
["-hide_banner", "-stats"], description="Misc Ffmpeg starting arguments"
)
misc_args: list[str] = Field(..., description="Misc Ffmpeg starting arguments")
ext: str = Field(
".mov",
...,
description="Extension for Ffmpeg supported container (must be compatible with other proxy settings!)",
)
overwrite: bool = Field(
True,
...,
description="Whether or not to overwrite any existing proxy files on collision",
)


class Filters(BaseModel):
extension_whitelist: list[str] = Field(
[".mov", ".mp4", ".mxf", ".avi"],
...,
min_items=0,
unique_items=True,
description="Only transcode source media with these file extensions. Leave empty to disable.",
)
framerate_whitelist: list[int] = Field(
[24, 25, 30, 50, 60],
...,
min_items=0,
unique_items=True,
description="Only transcode source media with these framerates. Leave empty to disable.",
Expand All @@ -138,26 +130,26 @@ def check_are_file_extensions(cls, v):


class Broker(BaseModel):
broker_url: RedisDsn = Field("redis://192.168.1.19:6379/0")
url: RedisDsn = Field(..., description="Redis broker address")
job_expires: int = Field(
3600,
...,
description="How long until a queued proxy job expires if not received by a worker. Default: 1 hr",
)
result_expires: int = Field(
86400,
...,
description="How long until a proxy job's result is discared. Default: 1 day. Used by monitor webapp",
)


class Worker(BaseModel):
loglevel: str = Field("INFO", description="Worker loglevel")
loglevel: str = Field(..., description="Worker loglevel")
terminal_args: list[str] = Field(
...,
min_items=0,
description="Pre-command args. Use to invoke the command through another shell/terminal.",
)
celery_args: list[str] = Field(
["-l", "INFO", "-P", "solo", "--without-mingle", "--without-gossip"],
...,
min_items=0,
description="Pre-command args. Use to invoke the command through another shell/terminal.",
)
Expand Down Expand Up @@ -190,10 +182,11 @@ def customise_sources(
init_settings,
env_settings,
file_secret_settings,
):
) -> tuple[SettingsSourceCallable, ...]:
return (
env_settings,
load_toml_user,
file_secret_settings,
init_settings,
)

Expand Down
4 changes: 2 additions & 2 deletions src/proxima/settings/user_settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
version_constrain = true # DANGEROUS! If false, allows any version of worker to take jobs.

[paths]
proxy_path_root = "R:/ProxyMedia" # Proxy media retains source folder structure
ffmpeg_logfile_path = "R:/ProxyMedia/@logs"
proxy_root = "R:/ProxyMedia" # Proxy media retains source folder structure
ffmpeg_logfile_dir = "R:/ProxyMedia/@logs"
linkable_proxy_suffix_regex = [ "-\\d", "_\\d", "S\\d*" ] # -1, # _1, #_S001 respectively

[proxy]
Expand Down
2 changes: 1 addition & 1 deletion src/proxima/types/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def batch_info(self) -> str:
return str(
f"[cyan]{self.project} | {self.timeline}[/]\n"
f"[green]Linked {els} | [yellow]Requeued {elr} | [red]Failed {elf}\n"
f"{settings.proxy.preset_nickname} | {overwrite_warning}\n"
f"{settings.proxy.nickname} | {overwrite_warning}\n"
f"\n[bold][white]Total queueable now:[/bold] {len(self.batch)}\n"
)

Expand Down

0 comments on commit b11c5de

Please sign in to comment.