33800 Docs

← Retour

Proposition : Contrôle dynamique du nombre de jobs parallèles

Date : 25/01/2026 02:36 Status : ✅ VALIDÉ ET IMPLÉMENTÉ

Objectif

Permettre de changer dynamiquement le nombre de jobs parallèles (1, 2 ou 3) depuis le dashboard ai-jobs.html.

Cas d'usage

Plan

1. API ai-orchestrator (main.py)

Ajouter 2 nouveaux endpoints :

# Clé Redis pour stocker le nombre de jobs parallèles
PARALLEL_JOBS_KEY = "ai:worker:parallel_jobs"
DEFAULT_PARALLEL_JOBS = 2

@app.get("/api/worker/parallel")
async def get_parallel_jobs():
    """Get current parallel jobs count"""
    count = await redis_client.get(PARALLEL_JOBS_KEY)
    return {"parallel_jobs": int(count) if count else DEFAULT_PARALLEL_JOBS}

@app.post("/api/worker/parallel")
async def set_parallel_jobs(count: int = 2):
    """Set parallel jobs count (1-5)"""
    count = max(1, min(5, count))  # Clamp entre 1 et 5
    await redis_client.set(PARALLEL_JOBS_KEY, str(count))
    return {"parallel_jobs": count, "message": f"Parallel jobs set to {count}"}

Modifier job_worker() pour lire dynamiquement depuis Redis :

# Dans job_worker(), remplacer OLLAMA_PARALLEL_JOBS par:
parallel_count_raw = await redis_client.get(PARALLEL_JOBS_KEY)
parallel_count = int(parallel_count_raw) if parallel_count_raw else DEFAULT_PARALLEL_JOBS

2. Dashboard ai-jobs.html

Ajouter un contrôle à côté du bouton Pause :

<div class="parallel-control">
    <label>Parallel:</label>
    <select id="parallel-select" onchange="setParallelJobs(this.value)">
        <option value="1">1</option>
        <option value="2" selected>2</option>
        <option value="3">3</option>
    </select>
</div>

Ajouter le JavaScript :

async function loadParallelJobs() {
    const res = await fetch(API_BASE + '/api/worker/parallel');
    const data = await res.json();
    document.getElementById('parallel-select').value = data.parallel_jobs;
}

async function setParallelJobs(count) {
    await fetch(API_BASE + '/api/worker/parallel?count=' + count, { method: 'POST' });
}

3. Régénérer le dashboard

cd /stock_8to/33800-stack/monitoring && ./generate.sh

Fichiers modifiés

Fichier Modification
/stock_8to/33800-stack/projects/ai-orchestrator/app/main.py Endpoints parallel + lecture dynamique
/stock_8to/33800-stack/monitoring/generate.d/20-ai-jobs.sh Contrôle UI parallel

Risques

Validation requise