feat: implement tweakable utility workers concurrency, instead of hard-coded value set to 5

This commit is contained in:
Xoconoch
2025-08-29 08:33:23 -06:00
parent fe5e7964fa
commit 41db454414
5 changed files with 91 additions and 7 deletions

7
app.py
View File

@@ -51,7 +51,6 @@ if _umask_value:
# Defer logging setup; avoid failing on invalid UMASK
pass
# Import and initialize routes (this will start the watch manager)
from routes.auth.credentials import router as credentials_router # noqa: E402
from routes.auth.auth import router as auth_router # noqa: E402
@@ -65,14 +64,8 @@ from routes.core.history import router as history_router # noqa: E402
from routes.system.progress import router as prgs_router # noqa: E402
from routes.system.config import router as config_router # noqa: E402
# Import Celery configuration and manager
from routes.utils.celery_config import REDIS_URL # noqa: E402
# Import authentication system
# Import watch manager controls (start/stop) without triggering side effects
# Configure application-wide logging
def setup_logging():

View File

@@ -110,6 +110,76 @@ function SpotifyApiForm() {
);
}
function UtilityConcurrencyForm() {
const queryClient = useQueryClient();
const { data: configData, isLoading } = useQuery({
queryKey: ["config"],
queryFn: () => authApiClient.getConfig<any>(),
});
const { register, handleSubmit, reset, formState: { isDirty } } = useForm<{ utilityConcurrency: number }>();
useEffect(() => {
if (configData) {
reset({ utilityConcurrency: Number(configData.utilityConcurrency ?? 1) });
}
}, [configData, reset]);
const mutation = useMutation({
mutationFn: (payload: { utilityConcurrency: number }) => authApiClient.updateConfig(payload),
onSuccess: () => {
toast.success("Utility worker concurrency saved!");
queryClient.invalidateQueries({ queryKey: ["config"] });
},
onError: (e) => {
toast.error(`Failed to save: ${(e as any).message}`);
},
});
const onSubmit = (values: { utilityConcurrency: number }) => {
const value = Math.max(1, Number(values.utilityConcurrency || 1));
mutation.mutate({ utilityConcurrency: value });
};
if (isLoading) return <p className="text-content-muted dark:text-content-muted-dark">Loading server settings...</p>;
return (
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
<div className="flex items-center justify-end mb-2">
<div className="flex items-center gap-3">
<button
type="submit"
disabled={mutation.isPending || !isDirty}
className="px-4 py-2 bg-button-primary hover:bg-button-primary-hover text-button-primary-text rounded-md disabled:opacity-50"
title="Save Utility Concurrency"
>
{mutation.isPending ? (
<img src="/spinner.svg" alt="Saving" className="w-5 h-5 animate-spin logo" />
) : (
<img src="/save.svg" alt="Save" className="w-5 h-5 logo" />
)}
</button>
</div>
</div>
<div className="flex flex-col gap-2">
<label htmlFor="utilityConcurrency" className="text-content-primary dark:text-content-primary-dark">Utility Worker Concurrency</label>
<input
id="utilityConcurrency"
type="number"
min={1}
step={1}
{...register("utilityConcurrency", { valueAsNumber: true })}
className="block w-full p-2 border bg-input-background dark:bg-input-background-dark border-input-border dark:border-input-border-dark rounded-md focus:outline-none focus:ring-2 focus:ring-input-focus"
placeholder="1"
/>
<p className="text-xs text-content-secondary dark:text-content-secondary-dark">Controls concurrency of the utility Celery worker. Minimum 1.</p>
</div>
</form>
);
}
// --- Components ---
function WebhookForm() {
const queryClient = useQueryClient();
const { data, isLoading } = useQuery({ queryKey: ["webhookConfig"], queryFn: fetchWebhookConfig });
@@ -223,6 +293,12 @@ export function ServerTab() {
<SpotifyApiForm />
</div>
<hr className="border-border dark:border-border-dark" />
<div>
<h3 className="text-xl font-semibold text-content-primary dark:text-content-primary-dark">Utility Worker</h3>
<p className="text-sm text-content-muted dark:text-content-muted-dark mt-1">Tune background utility worker concurrency for low-powered systems.</p>
<UtilityConcurrencyForm />
</div>
<hr className="border-border dark:border-border-dark" />
<div>
<h3 className="text-xl font-semibold text-content-primary dark:text-content-primary-dark">Webhooks</h3>
<p className="text-sm text-content-muted dark:text-content-muted-dark mt-1">

View File

@@ -32,6 +32,7 @@ export type FlatAppSettings = {
deezer: string;
deezerQuality: "MP3_128" | "MP3_320" | "FLAC";
maxConcurrentDownloads: number;
utilityConcurrency: number;
realTime: boolean;
fallback: boolean;
convertTo: "MP3" | "AAC" | "OGG" | "OPUS" | "FLAC" | "WAV" | "ALAC" | "";
@@ -72,6 +73,7 @@ const defaultSettings: FlatAppSettings = {
deezer: "",
deezerQuality: "MP3_128",
maxConcurrentDownloads: 3,
utilityConcurrency: 1,
realTime: false,
fallback: false,
convertTo: "",
@@ -135,6 +137,7 @@ const fetchSettings = async (): Promise<FlatAppSettings> => {
// Ensure required frontend-only fields exist
recursiveQuality: Boolean((camelData as any).recursiveQuality ?? false),
realTimeMultiplier: Number((camelData as any).realTimeMultiplier ?? 0),
utilityConcurrency: Number((camelData as any).utilityConcurrency ?? 1),
// Ensure watch subkeys default if missing
watch: {
...(camelData.watch as any),

View File

@@ -8,6 +8,7 @@ export interface AppSettings {
deezer: string;
deezerQuality: "MP3_128" | "MP3_320" | "FLAC";
maxConcurrentDownloads: number;
utilityConcurrency: number;
realTime: boolean;
fallback: boolean;
convertTo: "MP3" | "AAC" | "OGG" | "OPUS" | "FLAC" | "WAV" | "ALAC" | "";

View File

@@ -369,6 +369,17 @@ class AuthApiClient {
get client() {
return this.apiClient;
}
// General config helpers
async getConfig<T = any>(): Promise<T> {
const response = await this.apiClient.get<T>("/config");
return response.data;
}
async updateConfig<T = any>(partial: Record<string, unknown>): Promise<T> {
const response = await this.apiClient.put<T>("/config", partial);
return response.data;
}
}
// Create and export a singleton instance