feat(scheduler): admin run-now/run-all triggers + live progress + completion notices
Add per-job "Run now" buttons and a "Start all now" button to the admin Scheduler dashboard (admin-gated endpoints). Triggers run the job in a background thread independent of its interval, refusing a concurrent run (409). While running, the long jobs (maintenance, enrich, backfill, shorts) report live progress through a decoupled contextvar sink, shown as a progress bar on the job row via the existing 4s poll. A manually-triggered run posts a completion notification to the triggering admin's inbox (scheduled runs stay silent to avoid spam); the inbox renders the "scheduler" type trilingually from type+data. While here, give the maintenance job its missing dashboard label/description in all three languages.
This commit is contained in:
parent
3a0789ebe7
commit
ed4194a8d3
15 changed files with 344 additions and 30 deletions
|
|
@ -117,10 +117,21 @@ function NotificationRow({
|
|||
// Known notification types are rendered from i18n (so they're trilingual) using the typed
|
||||
// payload; the server-stored title/body are an English fallback for any unknown type.
|
||||
const isMaintenance = n.type === "maintenance" && typeof n.data?.count === "number";
|
||||
const title = isMaintenance ? t("inbox.maintenance.title") : n.title;
|
||||
const body = isMaintenance
|
||||
? t("inbox.maintenance.body", { count: n.data!.count })
|
||||
: n.body;
|
||||
const isScheduler = n.type === "scheduler" && typeof n.data?.job_id === "string";
|
||||
let title = n.title;
|
||||
let body = n.body;
|
||||
if (isMaintenance) {
|
||||
title = t("inbox.maintenance.title");
|
||||
body = t("inbox.maintenance.body", { count: n.data!.count });
|
||||
} else if (isScheduler) {
|
||||
// "<Job label> finished/failed", with the raw result summary as the (technical) body.
|
||||
const job = t(`scheduler.jobs.${n.data!.job_id}`, n.data!.job_id);
|
||||
title = t(
|
||||
n.data!.status === "error" ? "inbox.jobDone.titleError" : "inbox.jobDone.titleOk",
|
||||
{ job }
|
||||
);
|
||||
body = n.data!.summary || n.body;
|
||||
}
|
||||
return (
|
||||
<div
|
||||
className={`glass rounded-xl p-3.5 flex items-start gap-3 transition ${
|
||||
|
|
|
|||
|
|
@ -73,14 +73,45 @@ function StatusLegend() {
|
|||
);
|
||||
}
|
||||
|
||||
function JobProgress({ p }: { p: NonNullable<SchedulerJob["progress"]> }) {
|
||||
const { t } = useTranslation();
|
||||
const phase = p.phase ? t(`scheduler.phase.${p.phase}`, p.phase) : null;
|
||||
const pct =
|
||||
p.total && p.total > 0 ? Math.min(100, Math.round((p.current / p.total) * 100)) : null;
|
||||
return (
|
||||
<div className="mt-1.5">
|
||||
<div className="flex items-center justify-between text-[11px] text-muted mb-0.5">
|
||||
<span className="truncate">{phase}</span>
|
||||
<span className="tabular-nums shrink-0">
|
||||
{p.total != null
|
||||
? `${p.current.toLocaleString()} / ${p.total.toLocaleString()}`
|
||||
: p.current.toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
<div className="h-1.5 rounded-full bg-border overflow-hidden">
|
||||
{pct != null ? (
|
||||
<div className="h-full rounded-full bg-accent transition-[width]" style={{ width: `${pct}%` }} />
|
||||
) : (
|
||||
// Indeterminate: total unknown, so a slim moving sliver instead of a fill.
|
||||
<div className="h-full w-1/3 rounded-full bg-accent animate-pulse" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function JobRow({
|
||||
job,
|
||||
onSave,
|
||||
saving,
|
||||
onRun,
|
||||
runDisabled,
|
||||
}: {
|
||||
job: SchedulerJob;
|
||||
onSave: (minutes: number) => void;
|
||||
saving: boolean;
|
||||
onRun: () => void;
|
||||
runDisabled: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [editing, setEditing] = useState(false);
|
||||
|
|
@ -153,6 +184,7 @@ function JobRow({
|
|||
<span> · {job.last_result}</span>
|
||||
) : null}
|
||||
</div>
|
||||
{job.running && job.progress && <JobProgress p={job.progress} />}
|
||||
</div>
|
||||
<div className="shrink-0 text-right text-[11px] text-muted tabular-nums">
|
||||
{job.running ? (
|
||||
|
|
@ -166,6 +198,16 @@ function JobRow({
|
|||
"—"
|
||||
)}
|
||||
</div>
|
||||
<Tooltip hint={t("scheduler.runNow")}>
|
||||
<button
|
||||
onClick={onRun}
|
||||
disabled={job.running || runDisabled}
|
||||
aria-label={t("scheduler.runNow")}
|
||||
className="shrink-0 p-1.5 rounded-lg text-muted hover:text-accent hover:bg-card transition disabled:opacity-30 disabled:hover:text-muted disabled:hover:bg-transparent"
|
||||
>
|
||||
<Play className="w-4 h-4" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -227,6 +269,23 @@ export default function Scheduler() {
|
|||
onError: () => notify({ level: "error", message: t("scheduler.intervalFailed") }),
|
||||
});
|
||||
|
||||
// Manual "run now" triggers. The wrapper runs in a background thread server-side; the
|
||||
// live poll surfaces the "running" state within a tick, so we just nudge a refetch.
|
||||
const runMut = useMutation({
|
||||
mutationFn: (jobId: string) => api.runSchedulerJob(jobId),
|
||||
onSuccess: (_d, jobId) => {
|
||||
notify({ level: "success", message: t("scheduler.triggered", { job: t(`scheduler.jobs.${jobId}`, jobId) }) });
|
||||
qc.invalidateQueries({ queryKey: ["scheduler"] });
|
||||
},
|
||||
});
|
||||
const runAllMut = useMutation({
|
||||
mutationFn: () => api.runAllSchedulerJobs(),
|
||||
onSuccess: (res) => {
|
||||
notify({ level: "success", message: t("scheduler.triggeredAll", { count: res.started.length }) });
|
||||
qc.invalidateQueries({ queryKey: ["scheduler"] });
|
||||
},
|
||||
});
|
||||
|
||||
if (q.isLoading && !data)
|
||||
return <div className="p-8 text-muted">{t("scheduler.loading")}</div>;
|
||||
if (!data)
|
||||
|
|
@ -260,6 +319,16 @@ export default function Scheduler() {
|
|||
</div>
|
||||
</div>
|
||||
<div className="flex-1" />
|
||||
<Tooltip hint={data.paused ? t("scheduler.runAllPausedHint") : t("scheduler.runAllHint")}>
|
||||
<button
|
||||
onClick={() => runAllMut.mutate()}
|
||||
disabled={runAllMut.isPending || data.paused}
|
||||
className="glass-card glass-hover flex items-center gap-2 px-3 py-2 rounded-xl text-sm disabled:opacity-50 transition"
|
||||
>
|
||||
<Play className="w-4 h-4" />
|
||||
{t("scheduler.runAll")}
|
||||
</button>
|
||||
</Tooltip>
|
||||
<Tooltip hint={t("scheduler.pauseHint")}>
|
||||
<button
|
||||
onClick={() => pauseResume.mutate(data.paused)}
|
||||
|
|
@ -290,6 +359,8 @@ export default function Scheduler() {
|
|||
job={job}
|
||||
saving={intervalMut.isPending}
|
||||
onSave={(minutes) => intervalMut.mutate({ jobId: job.id, minutes })}
|
||||
onRun={() => runMut.mutate(job.id)}
|
||||
runDisabled={data.paused || runAllMut.isPending}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -12,5 +12,9 @@
|
|||
"title": "Videos entfernt",
|
||||
"body_one": "{{count}} gespeichertes oder in einer Playlist befindliches Video wurde entfernt, weil es auf YouTube nicht mehr verfügbar ist.",
|
||||
"body_other": "{{count}} gespeicherte oder in Playlists befindliche Videos wurden entfernt, weil sie auf YouTube nicht mehr verfügbar sind."
|
||||
},
|
||||
"jobDone": {
|
||||
"titleOk": "{{job}} abgeschlossen",
|
||||
"titleError": "{{job}} fehlgeschlagen"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,21 @@
|
|||
"minutes": "Min",
|
||||
"editInterval": "Klicken, um das Intervall zu ändern",
|
||||
"intervalFailed": "Intervall konnte nicht geändert werden",
|
||||
"runNow": "Jetzt ausführen",
|
||||
"runAll": "Alle jetzt starten",
|
||||
"runAllHint": "Alle Jobs jetzt ausführen, zusätzlich zu ihren Zeitplänen.",
|
||||
"runAllPausedHint": "Setze den Planer fort, um Jobs auszuführen (pausiert werden sie übersprungen).",
|
||||
"triggered": "{{job}} gestartet",
|
||||
"triggeredAll_one": "{{count}} Job gestartet",
|
||||
"triggeredAll_other": "{{count}} Jobs gestartet",
|
||||
"phase": {
|
||||
"recheck": "Markierte Videos erneut prüfen",
|
||||
"revalidate": "Videos erneut validieren",
|
||||
"enrich": "Videos anreichern",
|
||||
"backfill_recent": "Neue Uploads nachladen",
|
||||
"backfill_deep": "Ganze Historie nachladen",
|
||||
"probe": "Shorts klassifizieren"
|
||||
},
|
||||
"dot": {
|
||||
"running": "läuft gerade",
|
||||
"ok": "letzter Lauf OK",
|
||||
|
|
@ -39,7 +54,8 @@
|
|||
"autotag": "Erkennt Sprache/Themen jedes Kanals und vergibt automatische Tags. Fällt er aus, bekommen neue Kanäle keine Auto-Tags, sodass Sprach-/Themenfilter sie verfehlen.",
|
||||
"shorts": "Prüft youtube.com/shorts, um Shorts zu markieren. Fällt er aus, werden Shorts im Feed nicht von normalen Videos getrennt.",
|
||||
"subscriptions": "Importiert die YouTube-Abos jedes Nutzers neu. Fällt er aus, werden auf YouTube hinzugefügte oder entfernte Abos hier nicht übernommen.",
|
||||
"playlist_sync": "Spiegelt die YouTube-Wiedergabelisten jedes Nutzers in die App. Fällt er aus, erscheinen Änderungen an deinen YouTube-Listen lokal nicht."
|
||||
"playlist_sync": "Spiegelt die YouTube-Wiedergabelisten jedes Nutzers in die App. Fällt er aus, erscheinen Änderungen an deinen YouTube-Listen lokal nicht.",
|
||||
"maintenance": "Findet Videos, die nicht mehr abspielbar sind (gelöscht, auf privat gesetzt, abgebrochene Premieren), blendet sie aus dem Feed aus und entfernt sie nach einer Schonfrist; prüft die am längsten nicht geprüften Videos erneut. Fällt er aus, bleiben tote Videos im Katalog."
|
||||
},
|
||||
"jobs": {
|
||||
"rss_poll": "RSS-Abfrage (neue Uploads)",
|
||||
|
|
@ -48,7 +64,8 @@
|
|||
"autotag": "Automatisches Tagging",
|
||||
"shorts": "Shorts-Klassifizierung",
|
||||
"subscriptions": "Abo-Resync",
|
||||
"playlist_sync": "YouTube-Wiedergabelisten-Sync"
|
||||
"playlist_sync": "YouTube-Wiedergabelisten-Sync",
|
||||
"maintenance": "Wartung + Validierung"
|
||||
},
|
||||
"queue": {
|
||||
"recentPending": "Zu synchronisierende Kanäle",
|
||||
|
|
|
|||
|
|
@ -12,5 +12,9 @@
|
|||
"title": "Videos removed",
|
||||
"body_one": "{{count}} saved or playlisted video was removed because it's no longer available on YouTube.",
|
||||
"body_other": "{{count}} saved or playlisted videos were removed because they're no longer available on YouTube."
|
||||
},
|
||||
"jobDone": {
|
||||
"titleOk": "{{job}} finished",
|
||||
"titleError": "{{job}} failed"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,21 @@
|
|||
"minutes": "min",
|
||||
"editInterval": "Click to change how often this runs",
|
||||
"intervalFailed": "Couldn't change the interval",
|
||||
"runNow": "Run now",
|
||||
"runAll": "Start all now",
|
||||
"runAllHint": "Run every job now, in addition to their schedules.",
|
||||
"runAllPausedHint": "Resume the scheduler to run jobs (they're skipped while paused).",
|
||||
"triggered": "Started {{job}}",
|
||||
"triggeredAll_one": "Started {{count}} job",
|
||||
"triggeredAll_other": "Started {{count}} jobs",
|
||||
"phase": {
|
||||
"recheck": "Re-checking flagged videos",
|
||||
"revalidate": "Re-validating videos",
|
||||
"enrich": "Enriching videos",
|
||||
"backfill_recent": "Backfilling recent uploads",
|
||||
"backfill_deep": "Backfilling full history",
|
||||
"probe": "Classifying Shorts"
|
||||
},
|
||||
"dot": {
|
||||
"running": "running now",
|
||||
"ok": "last run OK",
|
||||
|
|
@ -39,7 +54,8 @@
|
|||
"autotag": "Detects each channel's language/topics and applies automatic tags. If it stops, new channels get no auto tags, so language/topic filters miss them.",
|
||||
"shorts": "Probes youtube.com/shorts to mark which videos are Shorts. If it stops, Shorts aren't separated from normal videos in the feed.",
|
||||
"subscriptions": "Re-imports every user's YouTube subscriptions. If it stops, channels subscribed to or dropped on YouTube aren't reflected here.",
|
||||
"playlist_sync": "Mirrors each user's YouTube playlists into the app. If it stops, changes to your YouTube playlists don't show up locally."
|
||||
"playlist_sync": "Mirrors each user's YouTube playlists into the app. If it stops, changes to your YouTube playlists don't show up locally.",
|
||||
"maintenance": "Finds videos that can no longer be played (deleted, made private, abandoned premieres), hides them from the feed and removes them after a grace period; re-checks the least-recently-checked videos. If it stops, dead videos linger in the catalogue."
|
||||
},
|
||||
"jobs": {
|
||||
"rss_poll": "RSS poll (new uploads)",
|
||||
|
|
@ -48,7 +64,8 @@
|
|||
"autotag": "Auto-tagging",
|
||||
"shorts": "Shorts classification",
|
||||
"subscriptions": "Subscription resync",
|
||||
"playlist_sync": "YouTube playlist sync"
|
||||
"playlist_sync": "YouTube playlist sync",
|
||||
"maintenance": "Maintenance + validation"
|
||||
},
|
||||
"queue": {
|
||||
"recentPending": "Channels to sync",
|
||||
|
|
|
|||
|
|
@ -12,5 +12,9 @@
|
|||
"title": "Videók eltávolítva",
|
||||
"body_one": "{{count}} mentett vagy lejátszási listás videó eltávolítva, mert már nem elérhető a YouTube-on.",
|
||||
"body_other": "{{count}} mentett vagy lejátszási listás videó eltávolítva, mert már nem elérhetők a YouTube-on."
|
||||
},
|
||||
"jobDone": {
|
||||
"titleOk": "{{job}} kész",
|
||||
"titleError": "{{job}} hibázott"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,21 @@
|
|||
"minutes": "perc",
|
||||
"editInterval": "Kattints a gyakoriság módosításához",
|
||||
"intervalFailed": "Nem sikerült módosítani a gyakoriságot",
|
||||
"runNow": "Futtatás most",
|
||||
"runAll": "Mind indítása most",
|
||||
"runAllHint": "Minden feladat azonnali futtatása, az ütemezésükön felül.",
|
||||
"runAllPausedHint": "Folytasd az ütemezőt a futtatáshoz (szüneteltetve a feladatok kimaradnak).",
|
||||
"triggered": "Elindítva: {{job}}",
|
||||
"triggeredAll_one": "{{count}} feladat elindítva",
|
||||
"triggeredAll_other": "{{count}} feladat elindítva",
|
||||
"phase": {
|
||||
"recheck": "Megjelölt videók újraellenőrzése",
|
||||
"revalidate": "Videók újraellenőrzése",
|
||||
"enrich": "Videók dúsítása",
|
||||
"backfill_recent": "Friss feltöltések behúzása",
|
||||
"backfill_deep": "Teljes előzmény behúzása",
|
||||
"probe": "Shorts besorolás"
|
||||
},
|
||||
"dot": {
|
||||
"running": "most fut",
|
||||
"ok": "utolsó futás OK",
|
||||
|
|
@ -39,7 +54,8 @@
|
|||
"autotag": "Felismeri a csatornák nyelvét/témáit, és automatikus címkéket ad. Ha leáll, az új csatornák címke nélkül maradnak, így a nyelv/téma szűrők kihagyják őket.",
|
||||
"shorts": "A youtube.com/shorts próbával jelöli, mely videók Shorts-ok. Ha leáll, a Shorts-ok nem különülnek el a normál videóktól a hírfolyamban.",
|
||||
"subscriptions": "Újraimportálja minden felhasználó YouTube-feliratkozásait. Ha leáll, a YouTube-on felvett vagy törölt feliratkozások nem tükröződnek itt.",
|
||||
"playlist_sync": "Tükrözi a felhasználók YouTube lejátszási listáit az appba. Ha leáll, a YouTube-listák változásai nem jelennek meg lokálisan."
|
||||
"playlist_sync": "Tükrözi a felhasználók YouTube lejátszási listáit az appba. Ha leáll, a YouTube-listák változásai nem jelennek meg lokálisan.",
|
||||
"maintenance": "Megkeresi a már sehol le nem játszható videókat (törölt, priváttá tett, elhagyott premier), elrejti őket a hírfolyamból, és türelmi idő után eltávolítja; újraellenőrzi a legrégebben ellenőrzött videókat. Ha leáll, a halott videók a katalógusban maradnak."
|
||||
},
|
||||
"jobs": {
|
||||
"rss_poll": "RSS-lekérdezés (új feltöltések)",
|
||||
|
|
@ -48,7 +64,8 @@
|
|||
"autotag": "Automatikus címkézés",
|
||||
"shorts": "Shorts-besorolás",
|
||||
"subscriptions": "Feliratkozások újraszinkronja",
|
||||
"playlist_sync": "YouTube lejátszási listák szinkronja"
|
||||
"playlist_sync": "YouTube lejátszási listák szinkronja",
|
||||
"maintenance": "Karbantartás + ellenőrzés"
|
||||
},
|
||||
"queue": {
|
||||
"recentPending": "Szinkronra váró csatorna",
|
||||
|
|
|
|||
|
|
@ -325,6 +325,9 @@ export interface SchedulerJob {
|
|||
last_finished: string | null;
|
||||
last_result: string | null;
|
||||
last_error: string | null;
|
||||
// Live progress while running (null when idle or for jobs that don't report it).
|
||||
// total is null for indeterminate progress (e.g. enrichment drains an unknown queue).
|
||||
progress: { current: number; total: number | null; phase: string | null } | null;
|
||||
}
|
||||
|
||||
export interface SchedulerStatus {
|
||||
|
|
@ -467,6 +470,10 @@ export const api = {
|
|||
method: "PATCH",
|
||||
body: JSON.stringify({ interval_minutes: intervalMinutes }),
|
||||
}),
|
||||
runSchedulerJob: (jobId: string): Promise<{ id: string; started: boolean }> =>
|
||||
req(`/api/admin/scheduler/jobs/${jobId}/run`, { method: "POST" }),
|
||||
runAllSchedulerJobs: (): Promise<{ started: string[] }> =>
|
||||
req("/api/admin/scheduler/run-all", { method: "POST" }),
|
||||
|
||||
// --- onboarding / admin ---
|
||||
requestAccess: (email: string): Promise<{ status: string }> =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue