Compare commits
3 Commits
fe420b9455
...
6afbe82a29
| Author | SHA1 | Date | |
|---|---|---|---|
| 6afbe82a29 | |||
| 6bfc013e35 | |||
| f6a7f0ef5a |
@@ -1,58 +1,63 @@
|
|||||||
import { auth } from "@/auth";
|
import { auth } from "@/auth";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { StatsCards } from "@/components/dashboard/StatsCards";
|
import { StatsCards } from "@/components/dashboard/StatsCards";
|
||||||
|
import { BlockedQueue } from "@/components/dashboard/BlockedQueue";
|
||||||
|
import { FarmStrip } from "@/components/dashboard/FarmStrip";
|
||||||
|
import { DeliveryCountdown } from "@/components/dashboard/DeliveryCountdown";
|
||||||
|
import { QcQueue } from "@/components/dashboard/QcQueue";
|
||||||
|
import { RecentDeliveries } from "@/components/dashboard/RecentDeliveries";
|
||||||
|
import { WhoseCourt } from "@/components/dashboard/WhoseCourt";
|
||||||
import { ShotQueue } from "@/components/dashboard/ShotQueue";
|
import { ShotQueue } from "@/components/dashboard/ShotQueue";
|
||||||
import { RecentActivity } from "@/components/dashboard/RecentActivity";
|
|
||||||
import { TaskWidgets } from "@/components/dashboard/TaskWidgets";
|
import { TaskWidgets } from "@/components/dashboard/TaskWidgets";
|
||||||
import { ScheduleWidgets } from "@/components/dashboard/ScheduleWidgets";
|
import { ScheduleWidgets } from "@/components/dashboard/ScheduleWidgets";
|
||||||
|
import {
|
||||||
|
getBlockedExports,
|
||||||
|
getDeliveryCountdown,
|
||||||
|
getFarmStatus,
|
||||||
|
getOpsCounts,
|
||||||
|
getQcQueue,
|
||||||
|
getQcStaleHours,
|
||||||
|
getRecentDeliveries,
|
||||||
|
getWhoseCourt,
|
||||||
|
} from "@/lib/dashboard/ops";
|
||||||
import type { DashboardStats } from "@/types";
|
import type { DashboardStats } from "@/types";
|
||||||
|
|
||||||
export const metadata = { title: "Dashboard" };
|
export const metadata = { title: "Dashboard" };
|
||||||
|
|
||||||
|
// Queue depth and machine state are stale the moment they are cached.
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The dashboard answers one question: can we ship what is due, and what is
|
||||||
|
* stopping us? Everything on it is pipeline state — exports, QC, deliveries,
|
||||||
|
* worker heartbeats — rather than anything a person has to maintain by hand.
|
||||||
|
*/
|
||||||
async function getDashboardData(userId: string, role: string) {
|
async function getDashboardData(userId: string, role: string) {
|
||||||
const isArtist = role === "ARTIST";
|
const isArtist = role === "ARTIST";
|
||||||
const isClient = role === "CLIENT";
|
const isClient = role === "CLIENT";
|
||||||
const now = new Date();
|
|
||||||
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
||||||
const todayEnd = new Date(todayStart.getTime() + 86400000);
|
|
||||||
|
|
||||||
const [awaitingReview, needsRevisions, approved, activeProjects,
|
// Producers see the floor; an artist sees the failures that are theirs.
|
||||||
tasksDueToday, tasksInReview, tasksOverdue, myTasksCount] =
|
const [counts, blocked, farm, episodes, qcQueue, qcStaleHours, deliveries, court] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
db.version.count({ where: { approvalStatus: "PENDING_REVIEW" } }),
|
getOpsCounts(isArtist ? userId : undefined),
|
||||||
db.version.count({ where: { approvalStatus: "NEEDS_CHANGES" } }),
|
getBlockedExports(isArtist ? { artistId: userId } : {}),
|
||||||
db.version.count({ where: { approvalStatus: "APPROVED" } }),
|
getFarmStatus(),
|
||||||
db.project.count({ where: { status: "ACTIVE" } }),
|
getDeliveryCountdown(),
|
||||||
db.task.count({
|
isArtist || isClient ? [] : getQcQueue(),
|
||||||
where: {
|
getQcStaleHours(),
|
||||||
dueDate: { gte: todayStart, lt: todayEnd },
|
isArtist || isClient ? [] : getRecentDeliveries(),
|
||||||
status: { not: "DONE" },
|
isArtist || isClient ? null : getWhoseCourt(),
|
||||||
...(isArtist ? { assignedArtistId: userId } : {}),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
db.task.count({
|
|
||||||
where: {
|
|
||||||
status: { in: ["INTERNAL_REVIEW", "CLIENT_REVIEW"] },
|
|
||||||
...(isArtist ? { assignedArtistId: userId } : {}),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
db.task.count({
|
|
||||||
where: {
|
|
||||||
dueDate: { lt: todayStart },
|
|
||||||
status: { not: "DONE" },
|
|
||||||
...(isArtist ? { assignedArtistId: userId } : {}),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
db.task.count({
|
|
||||||
where: { assignedArtistId: userId, status: { not: "DONE" } },
|
|
||||||
}),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const shotsWhere = isArtist ? { artistId: userId } : {};
|
// An artist's own shots come first; everyone else sees the floor.
|
||||||
const shots = await db.shot.findMany({
|
const shots = await db.shot.findMany({
|
||||||
where: { ...shotsWhere, status: { not: "COMPLETE" } },
|
where: {
|
||||||
|
...(isArtist ? { artistId: userId } : {}),
|
||||||
|
status: { not: "COMPLETE" },
|
||||||
|
project: { status: { in: ["ACTIVE", "ON_HOLD"] } },
|
||||||
|
},
|
||||||
take: 15,
|
take: 15,
|
||||||
orderBy: { updatedAt: "desc" },
|
orderBy: [{ dueDate: { sort: "asc", nulls: "last" } }, { updatedAt: "desc" }],
|
||||||
include: {
|
include: {
|
||||||
artist: { select: { id: true, name: true, image: true, email: true } },
|
artist: { select: { id: true, name: true, image: true, email: true } },
|
||||||
versions: {
|
versions: {
|
||||||
@@ -63,12 +68,8 @@ async function getDashboardData(userId: string, role: string) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// My tasks (for widget)
|
|
||||||
const myTasks = await db.task.findMany({
|
const myTasks = await db.task.findMany({
|
||||||
where: {
|
where: { assignedArtistId: userId, status: { not: "DONE" } },
|
||||||
assignedArtistId: userId,
|
|
||||||
status: { not: "DONE" },
|
|
||||||
},
|
|
||||||
take: 8,
|
take: 8,
|
||||||
orderBy: [{ dueDate: "asc" }, { priority: "desc" }],
|
orderBy: [{ dueDate: "asc" }, { priority: "desc" }],
|
||||||
include: {
|
include: {
|
||||||
@@ -78,7 +79,6 @@ async function getDashboardData(userId: string, role: string) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tasks in review (for supervisors/producers)
|
|
||||||
const reviewTasks = isArtist || isClient ? [] : await db.task.findMany({
|
const reviewTasks = isArtist || isClient ? [] : await db.task.findMany({
|
||||||
where: { status: { in: ["INTERNAL_REVIEW", "CLIENT_REVIEW"] } },
|
where: { status: { in: ["INTERNAL_REVIEW", "CLIENT_REVIEW"] } },
|
||||||
take: 8,
|
take: 8,
|
||||||
@@ -91,14 +91,8 @@ async function getDashboardData(userId: string, role: string) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const activity = await db.notification.findMany({
|
// Schedule overview (producers/supervisors/admins) — unchanged; it reads the
|
||||||
where: isClient ? { userId } : {},
|
// schedule page's own data rather than anything the pipeline owns.
|
||||||
take: 20,
|
|
||||||
orderBy: { createdAt: "desc" },
|
|
||||||
include: { user: { select: { name: true, image: true } } },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Schedule data (for producers/supervisors/admins)
|
|
||||||
const scheduledTasks =
|
const scheduledTasks =
|
||||||
!isArtist && !isClient
|
!isArtist && !isClient
|
||||||
? await db.task.findMany({
|
? await db.task.findMany({
|
||||||
@@ -119,43 +113,52 @@ async function getDashboardData(userId: string, role: string) {
|
|||||||
!isArtist && !isClient
|
!isArtist && !isClient
|
||||||
? await db.user.findMany({
|
? await db.user.findMany({
|
||||||
where: { isActive: true, role: { not: "CLIENT" } },
|
where: { isActive: true, role: { not: "CLIENT" } },
|
||||||
select: {
|
select: { id: true, name: true, email: true, image: true, role: true },
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
email: true,
|
|
||||||
image: true,
|
|
||||||
role: true,
|
|
||||||
},
|
|
||||||
orderBy: { name: "asc" },
|
orderBy: { name: "asc" },
|
||||||
})
|
})
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const stats: DashboardStats = {
|
const stats: DashboardStats = counts;
|
||||||
awaitingReview,
|
|
||||||
needsRevisions,
|
|
||||||
approved,
|
|
||||||
overdue: tasksOverdue,
|
|
||||||
activeProjects,
|
|
||||||
tasksDueToday,
|
|
||||||
tasksInReview,
|
|
||||||
tasksOverdue,
|
|
||||||
myTasksCount,
|
|
||||||
};
|
|
||||||
|
|
||||||
return { stats, shots, activity, myTasks, reviewTasks, scheduledTasks, scheduleArtists };
|
return {
|
||||||
|
stats,
|
||||||
|
blocked,
|
||||||
|
farm,
|
||||||
|
episodes,
|
||||||
|
qcQueue,
|
||||||
|
qcStaleHours,
|
||||||
|
deliveries,
|
||||||
|
court,
|
||||||
|
shots,
|
||||||
|
myTasks,
|
||||||
|
reviewTasks,
|
||||||
|
scheduledTasks,
|
||||||
|
scheduleArtists,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function DashboardPage() {
|
export default async function DashboardPage() {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
if (!session?.user) return null;
|
if (!session?.user) return null;
|
||||||
|
|
||||||
const { stats, shots, activity, myTasks, reviewTasks, scheduledTasks, scheduleArtists } =
|
|
||||||
await getDashboardData(session.user.id, session.user.role);
|
|
||||||
|
|
||||||
const isClient = session.user.role === "CLIENT";
|
const isClient = session.user.role === "CLIENT";
|
||||||
const canSeeSchedule = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(
|
const isArtistRole = session.user.role === "ARTIST";
|
||||||
session.user.role
|
const canSeeSchedule = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role);
|
||||||
);
|
const {
|
||||||
|
stats,
|
||||||
|
blocked,
|
||||||
|
farm,
|
||||||
|
episodes,
|
||||||
|
qcQueue,
|
||||||
|
qcStaleHours,
|
||||||
|
deliveries,
|
||||||
|
court,
|
||||||
|
shots,
|
||||||
|
myTasks,
|
||||||
|
reviewTasks,
|
||||||
|
scheduledTasks,
|
||||||
|
scheduleArtists,
|
||||||
|
} = await getDashboardData(session.user.id, session.user.role);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-8 space-y-6 max-w-[1600px] mx-auto">
|
<div className="p-8 space-y-6 max-w-[1600px] mx-auto">
|
||||||
@@ -166,7 +169,62 @@ export default async function DashboardPage() {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<StatsCards stats={stats} />
|
{!isClient && <StatsCards stats={stats} />}
|
||||||
|
|
||||||
|
{!isClient && (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
|
Delivery countdown
|
||||||
|
</h2>
|
||||||
|
<DeliveryCountdown episodes={episodes} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isClient && (
|
||||||
|
<div id="blocked" className="grid grid-cols-1 xl:grid-cols-3 gap-6 items-start scroll-mt-6">
|
||||||
|
<div className="xl:col-span-2 space-y-3">
|
||||||
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
|
{isArtistRole ? "Your blocked shots" : "Blocked — needs a human"}
|
||||||
|
</h2>
|
||||||
|
<BlockedQueue blocked={blocked} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
|
Render farm
|
||||||
|
</h2>
|
||||||
|
<FarmStrip farm={farm} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isClient && !isArtistRole && (
|
||||||
|
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6 items-start">
|
||||||
|
<div className="xl:col-span-2 space-y-3">
|
||||||
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
|
QC queue
|
||||||
|
</h2>
|
||||||
|
<QcQueue entries={qcQueue} staleHours={qcStaleHours} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-6">
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
|
Deliveries
|
||||||
|
</h2>
|
||||||
|
<RecentDeliveries deliveries={deliveries} />
|
||||||
|
</div>
|
||||||
|
{court && (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
|
Whose court
|
||||||
|
</h2>
|
||||||
|
<WhoseCourt court={court} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{!isClient && (
|
{!isClient && (
|
||||||
<TaskWidgets
|
<TaskWidgets
|
||||||
@@ -181,30 +239,16 @@ export default async function DashboardPage() {
|
|||||||
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
Schedule Overview
|
Schedule Overview
|
||||||
</h2>
|
</h2>
|
||||||
<ScheduleWidgets
|
<ScheduleWidgets scheduledTasks={scheduledTasks as any} artists={scheduleArtists} />
|
||||||
scheduledTasks={scheduledTasks as any}
|
|
||||||
artists={scheduleArtists}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6">
|
<div className="space-y-3">
|
||||||
<div className="xl:col-span-2 space-y-3">
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
{session.user.role === "ARTIST" ? "My shots" : "Shots in flight"}
|
||||||
Shot Queue
|
</h2>
|
||||||
</h2>
|
<div className="rounded-lg border border-border bg-card p-1">
|
||||||
<div className="rounded-lg border border-border bg-card p-1">
|
<ShotQueue shots={shots as any} />
|
||||||
<ShotQueue shots={shots as any} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-3">
|
|
||||||
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
|
||||||
Recent Activity
|
|
||||||
</h2>
|
|
||||||
<div className="rounded-lg border border-border bg-card h-[400px] overflow-hidden">
|
|
||||||
<RecentActivity activities={activity as any} />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -51,14 +51,16 @@ interface QueueExport {
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
projects: { id: string; name: string; code: string }[];
|
projects: { id: string; name: string; code: string }[];
|
||||||
|
/** Status to open filtered to, from `?status=` (see page.tsx). */
|
||||||
|
initialStatus?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PipelineQueueClient({ projects }: Props) {
|
export function PipelineQueueClient({ projects, initialStatus = "all" }: Props) {
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [projectId, setProjectId] = useState<string>("all");
|
const [projectId, setProjectId] = useState<string>("all");
|
||||||
const [statusFilter, setStatusFilter] = useState<string>("all");
|
const [statusFilter, setStatusFilter] = useState<string>(initialStatus);
|
||||||
const isAdmin = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session?.user?.role ?? "");
|
const isAdmin = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session?.user?.role ?? "");
|
||||||
|
|
||||||
const { data, isLoading, refetch, isFetching } = useQuery({
|
const { data, isLoading, refetch, isFetching } = useQuery({
|
||||||
|
|||||||
@@ -1,20 +1,32 @@
|
|||||||
import { auth } from "@/auth";
|
import { auth } from "@/auth";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
import { ExportStatus } from "@prisma/client";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { PipelineQueueClient } from "./PipelineQueueClient";
|
import { PipelineQueueClient } from "./PipelineQueueClient";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export default async function PipelinePage() {
|
export default async function PipelinePage({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
|
searchParams: Promise<{ status?: string }>;
|
||||||
|
}) {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
if (!session?.user) redirect("/login");
|
if (!session?.user) redirect("/login");
|
||||||
if (session.user.role === "CLIENT") redirect("/dashboard");
|
if (session.user.role === "CLIENT") redirect("/dashboard");
|
||||||
|
|
||||||
|
// Lets other pages link straight to a filtered queue — the dashboard's "In
|
||||||
|
// QC" figure is only useful if it leads to the rows it counted. Anything
|
||||||
|
// that is not a real status falls back to the unfiltered queue.
|
||||||
|
const requested = (await searchParams).status;
|
||||||
|
const initialStatus =
|
||||||
|
requested && (Object.values(ExportStatus) as string[]).includes(requested) ? requested : "all";
|
||||||
|
|
||||||
const projects = await db.project.findMany({
|
const projects = await db.project.findMany({
|
||||||
where: { status: { in: ["ACTIVE", "ON_HOLD"] } },
|
where: { status: { in: ["ACTIVE", "ON_HOLD"] } },
|
||||||
select: { id: true, name: true, code: true },
|
select: { id: true, name: true, code: true },
|
||||||
orderBy: { name: "asc" },
|
orderBy: { name: "asc" },
|
||||||
});
|
});
|
||||||
|
|
||||||
return <PipelineQueueClient projects={projects} />;
|
return <PipelineQueueClient projects={projects} initialStatus={initialStatus} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { formatDistanceToNowStrict } from "date-fns";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { EXPORT_STATUS_STYLES, statusLabel } from "@/app/(dashboard)/pipeline/status-colors";
|
||||||
|
import type { BlockedExport } from "@/lib/dashboard/ops";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The exception list: exports that have stopped moving and need a person.
|
||||||
|
*
|
||||||
|
* Read by scanning down the left edge — the severity rail says which rows are
|
||||||
|
* dead in the water (a failed state, which nothing retries) versus merely
|
||||||
|
* overdue (still nominally in flight, or waiting on a QC pass). The reason
|
||||||
|
* column exists so the answer to "what happened" doesn't require opening
|
||||||
|
* anything.
|
||||||
|
*/
|
||||||
|
export function BlockedQueue({ blocked }: { blocked: BlockedExport[] }) {
|
||||||
|
const critical = blocked.filter((b) => b.severity === "critical").length;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-zinc-800 bg-card overflow-hidden">
|
||||||
|
<div className="flex items-center justify-between gap-3 border-b border-zinc-800/60 px-4 py-3">
|
||||||
|
<h3 className="text-sm font-semibold text-white">
|
||||||
|
{blocked.length === 0
|
||||||
|
? "Nothing blocked"
|
||||||
|
: `${blocked.length} export${blocked.length === 1 ? "" : "s"} stalled`}
|
||||||
|
{critical > 0 && (
|
||||||
|
<span className="ml-2 text-xs font-normal text-red-400">{critical} failed</span>
|
||||||
|
)}
|
||||||
|
</h3>
|
||||||
|
<Link href="/pipeline" className="text-xs text-zinc-400 hover:text-amber-400">
|
||||||
|
Open render queue →
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{blocked.length === 0 ? (
|
||||||
|
<p className="px-4 py-10 text-center text-sm text-zinc-500">
|
||||||
|
Every export is either moving or done.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="w-full text-sm">
|
||||||
|
<thead>
|
||||||
|
<tr className="border-b border-zinc-800 bg-zinc-900/60 text-left text-xs text-zinc-400">
|
||||||
|
<th className="w-[3px] p-0" />
|
||||||
|
<th className="px-4 py-2.5 font-medium">Shot</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Status</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium whitespace-nowrap">Stuck</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Why</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Artist</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{blocked.map((b) => (
|
||||||
|
<tr key={b.exportId} className="border-b border-zinc-800/60 hover:bg-zinc-900/40">
|
||||||
|
<td className="w-[3px] p-0">
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"h-9 w-[3px]",
|
||||||
|
b.severity === "critical" ? "bg-red-500" : "bg-amber-500"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2.5">
|
||||||
|
<Link
|
||||||
|
href={`/pipeline/exports/${b.exportId}`}
|
||||||
|
className="font-mono text-[13px] font-medium text-white hover:text-amber-400"
|
||||||
|
>
|
||||||
|
{b.shotCode}{" "}
|
||||||
|
<span className="text-zinc-500">{b.versionString}</span>
|
||||||
|
</Link>
|
||||||
|
<div className="text-xs text-zinc-500">
|
||||||
|
{b.projectCode}
|
||||||
|
{b.episode ? ` · ep ${b.episode}` : ""}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2.5">
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"inline-block rounded-full border px-2 py-0.5 text-xs whitespace-nowrap",
|
||||||
|
EXPORT_STATUS_STYLES[b.status] ?? "bg-zinc-500/15 text-zinc-300 border-zinc-500/30"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{statusLabel(b.status)}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
className={cn(
|
||||||
|
"px-4 py-2.5 tabular-nums whitespace-nowrap",
|
||||||
|
b.severity === "critical" ? "text-red-400" : "text-zinc-300"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{formatDistanceToNowStrict(b.since)}
|
||||||
|
</td>
|
||||||
|
{/* The reason can be an aerender error several lines long;
|
||||||
|
it is clamped here and given in full on hover. */}
|
||||||
|
<td className="px-4 py-2.5 text-zinc-400 max-w-md" title={b.reason}>
|
||||||
|
<span className="line-clamp-2">{b.reason}</span>
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2.5 text-zinc-300 whitespace-nowrap">
|
||||||
|
{b.artistName ?? "—"}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { format } from "date-fns";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import type { CountdownVerdict, EpisodeCountdown } from "@/lib/dashboard/ops";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are we going to make the date? One card per episode, sorted by how soon.
|
||||||
|
*
|
||||||
|
* The bar is the episode's shots by where they actually are, and the row under
|
||||||
|
* it is the only comparison that matters: shots per day still needed against
|
||||||
|
* shots per day the studio has managed this week.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const VERDICT: Record<CountdownVerdict, { rail: string; chip: string; label: string }> = {
|
||||||
|
overdue: { rail: "bg-red-500", chip: "text-red-400 bg-red-500/10", label: "Overdue" },
|
||||||
|
behind: { rail: "bg-red-500", chip: "text-red-400 bg-red-500/10", label: "Behind" },
|
||||||
|
stalled: { rail: "bg-red-500", chip: "text-red-400 bg-red-500/10", label: "Nothing delivered this week" },
|
||||||
|
tight: { rail: "bg-amber-500", chip: "text-amber-400 bg-amber-500/10", label: "No slack" },
|
||||||
|
ahead: { rail: "bg-green-500", chip: "text-green-400 bg-green-500/10", label: "On track" },
|
||||||
|
complete: { rail: "bg-emerald-500", chip: "text-emerald-400 bg-emerald-500/10", label: "All delivered" },
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Two decimals is false precision for a shot count; one is the real resolution. */
|
||||||
|
const perDay = (n: number) => n.toFixed(1);
|
||||||
|
|
||||||
|
export function DeliveryCountdown({ episodes }: { episodes: EpisodeCountdown[] }) {
|
||||||
|
if (episodes.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-zinc-800 bg-card px-4 py-8 text-center text-sm text-zinc-500">
|
||||||
|
No delivery dates set. Add them on a project's Episodes tab to see the countdown here.
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="grid gap-4 grid-cols-1 md:grid-cols-2 xl:grid-cols-3">
|
||||||
|
{episodes.map((ep) => {
|
||||||
|
const verdict = VERDICT[ep.verdict];
|
||||||
|
const pct = (n: number) => (ep.total === 0 ? 0 : (n / ep.total) * 100);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
key={`${ep.projectId}:${ep.episode ?? ""}`}
|
||||||
|
href={`/shot-status?projectId=${ep.projectId}`}
|
||||||
|
className="group relative flex flex-col gap-3.5 overflow-hidden rounded-lg border border-zinc-800 bg-card p-4 pl-[18px] transition-colors hover:border-zinc-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500"
|
||||||
|
>
|
||||||
|
{/* Severity rail — the card itself stays neutral so only the
|
||||||
|
episode in trouble pulls the eye. */}
|
||||||
|
<span className={cn("absolute inset-y-0 left-0 w-[3px]", verdict.rail)} aria-hidden="true" />
|
||||||
|
|
||||||
|
<div className="flex items-start justify-between gap-3">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<div className="truncate text-[15px] font-semibold text-white">
|
||||||
|
{ep.projectCode}
|
||||||
|
{ep.episode && <span className="font-normal text-zinc-500"> · ep {ep.episode}</span>}
|
||||||
|
</div>
|
||||||
|
<div className="mt-0.5 text-xs text-zinc-400">
|
||||||
|
Due {format(ep.dueDate, "EEE d MMM yyyy")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="shrink-0 text-right">
|
||||||
|
<b className="block text-3xl font-bold leading-none tabular-nums text-white">
|
||||||
|
{Math.abs(ep.daysLeft)}
|
||||||
|
</b>
|
||||||
|
<small className="text-[11px] uppercase tracking-wide text-zinc-500">
|
||||||
|
{ep.daysLeft < 0 ? "days over" : "days left"}
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
className="flex h-2 overflow-hidden rounded-full bg-zinc-800"
|
||||||
|
role="img"
|
||||||
|
aria-label={`${ep.delivered} of ${ep.total} shots delivered, ${ep.inQc} through QC, ${ep.inProgress} in progress`}
|
||||||
|
>
|
||||||
|
<i className="block h-full bg-emerald-500" style={{ width: `${pct(ep.delivered)}%` }} />
|
||||||
|
<i className="block h-full bg-amber-500" style={{ width: `${pct(ep.inQc)}%` }} />
|
||||||
|
<i className="block h-full bg-blue-500" style={{ width: `${pct(ep.inProgress)}%` }} />
|
||||||
|
</div>
|
||||||
|
<div className="mt-2 flex flex-wrap gap-x-3 gap-y-1 text-xs text-zinc-400">
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<i className="h-2 w-2 rounded-sm bg-emerald-500" /> {ep.delivered} delivered
|
||||||
|
</span>
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<i className="h-2 w-2 rounded-sm bg-amber-500" /> {ep.inQc} in QC
|
||||||
|
</span>
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<i className="h-2 w-2 rounded-sm bg-blue-500" /> {ep.inProgress} in progress
|
||||||
|
</span>
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<i className="h-2 w-2 rounded-sm bg-zinc-700" /> {ep.notStarted} not started
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between gap-3 border-t border-zinc-800/60 pt-3">
|
||||||
|
<div>
|
||||||
|
<div className="text-[11px] text-zinc-500">Needed / day</div>
|
||||||
|
<div className="font-mono text-[15px] tabular-nums text-white">
|
||||||
|
{perDay(ep.requiredPerDay)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="text-[11px] text-zinc-500">Last 7 days</div>
|
||||||
|
<div className="font-mono text-[15px] tabular-nums text-white">
|
||||||
|
{perDay(ep.actualPerDay)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span className={cn("rounded-full px-2.5 py-1 text-xs font-semibold", verdict.chip)}>
|
||||||
|
{ep.verdict === "behind" && ep.daysBehind
|
||||||
|
? `${ep.daysBehind} day${ep.daysBehind === 1 ? "" : "s"} behind`
|
||||||
|
: ep.verdict === "overdue" && ep.daysBehind
|
||||||
|
? `${ep.daysBehind} day${ep.daysBehind === 1 ? "" : "s"} over`
|
||||||
|
: verdict.label}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { formatDistanceToNowStrict } from "date-fns";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { formatEta } from "@/app/(dashboard)/pipeline/status-colors";
|
||||||
|
import type { FarmStatus } from "@/lib/dashboard/ops";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Farm health: who is up, what is waiting, and who is running an old worker.
|
||||||
|
*
|
||||||
|
* The version row is not trivia — a worker's version is what decides whether
|
||||||
|
* it has a given fix, and a machine that quietly stayed behind keeps producing
|
||||||
|
* the bug everyone else has stopped seeing.
|
||||||
|
*/
|
||||||
|
export function FarmStrip({ farm }: { farm: FarmStatus }) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-zinc-800 bg-card overflow-hidden">
|
||||||
|
<div className="flex items-center justify-between gap-3 border-b border-zinc-800/60 px-4 py-3">
|
||||||
|
<h3 className="text-sm font-semibold text-white">
|
||||||
|
{farm.online} of {farm.total} online
|
||||||
|
</h3>
|
||||||
|
<Link href="/pipeline/machines" className="text-xs text-zinc-400 hover:text-amber-400">
|
||||||
|
Machines →
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{farm.machines.length === 0 ? (
|
||||||
|
<p className="px-4 py-8 text-center text-sm text-zinc-500">
|
||||||
|
No machines have registered yet.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
farm.machines.map((m) => (
|
||||||
|
<div
|
||||||
|
key={m.id}
|
||||||
|
className="flex items-center gap-3 border-b border-zinc-800/60 px-4 py-2.5 last:border-b-0"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"h-2 w-2 shrink-0 rounded-full",
|
||||||
|
m.status === "ONLINE"
|
||||||
|
? "bg-green-500 ring-4 ring-green-500/15"
|
||||||
|
: m.status === "DISABLED"
|
||||||
|
? "bg-zinc-600"
|
||||||
|
: "bg-zinc-500"
|
||||||
|
)}
|
||||||
|
title={m.status}
|
||||||
|
/>
|
||||||
|
<span className="w-24 shrink-0 font-mono text-[12.5px] text-white">{m.name}</span>
|
||||||
|
<span className="min-w-0 flex-1 truncate text-[12.5px] text-zinc-400">
|
||||||
|
{m.currentJob
|
||||||
|
? `${m.currentJob.shotCode ?? "job"} ${m.currentJob.versionString ?? ""} · ${Math.round(
|
||||||
|
(m.currentJob.progress ?? 0) * 100
|
||||||
|
)}% · ETA ${formatEta(m.currentJob.etaSeconds)}`
|
||||||
|
: m.status === "ONLINE"
|
||||||
|
? "Idle"
|
||||||
|
: m.lastSeenAt
|
||||||
|
? `Offline · last seen ${formatDistanceToNowStrict(new Date(m.lastSeenAt))} ago`
|
||||||
|
: "Never seen"}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"shrink-0 font-mono text-[11.5px]",
|
||||||
|
farm.latestWorkerVersion && m.workerVersion !== farm.latestWorkerVersion
|
||||||
|
? "text-amber-400"
|
||||||
|
: "text-zinc-500"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{m.workerVersion ?? "—"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="grid grid-cols-3 border-t border-zinc-800/60">
|
||||||
|
<div className="border-r border-zinc-800/60 px-4 py-2.5">
|
||||||
|
<b className="block font-mono text-lg font-semibold leading-tight text-white">
|
||||||
|
{farm.queued.render}
|
||||||
|
</b>
|
||||||
|
<small className="text-xs text-zinc-500">renders queued</small>
|
||||||
|
</div>
|
||||||
|
<div className="border-r border-zinc-800/60 px-4 py-2.5">
|
||||||
|
<b className="block font-mono text-lg font-semibold leading-tight text-white">
|
||||||
|
{farm.queued.preview}
|
||||||
|
</b>
|
||||||
|
<small className="text-xs text-zinc-500">previews queued</small>
|
||||||
|
</div>
|
||||||
|
<div className="px-4 py-2.5">
|
||||||
|
<b className="block font-mono text-lg font-semibold leading-tight text-white">
|
||||||
|
{farm.oldestQueuedMs == null
|
||||||
|
? "—"
|
||||||
|
: formatDistanceToNowStrict(new Date(Date.now() - farm.oldestQueuedMs))}
|
||||||
|
</b>
|
||||||
|
<small className="text-xs text-zinc-500">oldest wait</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{farm.behindMachines.length > 0 && (
|
||||||
|
<div className="flex gap-2 border-t border-amber-500/20 bg-amber-500/[0.07] px-4 py-2.5 text-xs text-amber-400">
|
||||||
|
<span aria-hidden="true">▲</span>
|
||||||
|
<span>
|
||||||
|
{farm.behindMachines.length} machine
|
||||||
|
{farm.behindMachines.length === 1 ? " is" : "s are"} behind{" "}
|
||||||
|
<span className="font-mono">{farm.latestWorkerVersion}</span> —{" "}
|
||||||
|
{farm.behindMachines
|
||||||
|
.map((m) => `${m.name} (${m.workerVersion ?? "unknown"})`)
|
||||||
|
.join(", ")}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { formatDistanceToNowStrict } from "date-fns";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import type { QcQueueEntry } from "@/lib/dashboard/ops";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What is waiting on someone to watch the frames, oldest first.
|
||||||
|
*
|
||||||
|
* Everything upstream of QC is worked by the farm; this is the one stage that
|
||||||
|
* only drains when a person sits down to it, which is why depth here is worth
|
||||||
|
* a panel of its own rather than a filter on the queue page.
|
||||||
|
*/
|
||||||
|
export function QcQueue({ entries, staleHours }: { entries: QcQueueEntry[]; staleHours: number }) {
|
||||||
|
const oldest = entries[0];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-zinc-800 bg-card overflow-hidden">
|
||||||
|
<div className="flex items-center justify-between gap-3 border-b border-zinc-800/60 px-4 py-3">
|
||||||
|
<h3 className="text-sm font-semibold text-white">
|
||||||
|
{entries.length === 0
|
||||||
|
? "QC queue empty"
|
||||||
|
: `${entries.length} waiting on QC`}
|
||||||
|
{oldest && (
|
||||||
|
<span className="ml-2 text-xs font-normal text-zinc-500">
|
||||||
|
oldest {formatDistanceToNowStrict(oldest.since)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</h3>
|
||||||
|
<Link
|
||||||
|
href="/pipeline?status=READY_FOR_QC"
|
||||||
|
className="text-xs text-zinc-400 hover:text-amber-400"
|
||||||
|
>
|
||||||
|
Open QC →
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{entries.length === 0 ? (
|
||||||
|
<p className="px-4 py-10 text-center text-sm text-zinc-500">
|
||||||
|
Nothing is waiting on a QC pass.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="w-full text-sm">
|
||||||
|
<thead>
|
||||||
|
<tr className="border-b border-zinc-800 bg-zinc-900/60 text-left text-xs text-zinc-400">
|
||||||
|
<th className="px-4 py-2.5 font-medium">Shot</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Version</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Waiting</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Frames</th>
|
||||||
|
<th className="px-4 py-2.5 font-medium">Submitted by</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{entries.map((e) => {
|
||||||
|
const stale = Date.now() - e.since.getTime() > staleHours * 3600_000;
|
||||||
|
return (
|
||||||
|
<tr key={e.exportId} className="border-b border-zinc-800/60 hover:bg-zinc-900/40">
|
||||||
|
<td className="px-4 py-2.5">
|
||||||
|
<Link
|
||||||
|
href={`/pipeline/exports/${e.exportId}`}
|
||||||
|
className="font-mono text-[13px] font-medium text-white hover:text-amber-400"
|
||||||
|
>
|
||||||
|
{e.shotCode}
|
||||||
|
</Link>
|
||||||
|
<div className="text-xs text-zinc-500">
|
||||||
|
{e.projectCode}
|
||||||
|
{e.episode ? ` · ep ${e.episode}` : ""}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2.5 font-mono text-[13px] text-zinc-300">
|
||||||
|
{e.versionString}
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
className={cn(
|
||||||
|
"px-4 py-2.5 tabular-nums whitespace-nowrap",
|
||||||
|
stale ? "text-amber-400" : "text-zinc-300"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{formatDistanceToNowStrict(e.since)}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2.5 font-mono text-[13px] tabular-nums text-zinc-400 whitespace-nowrap">
|
||||||
|
{e.frameStart}–{e.frameEnd}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2.5 text-zinc-300 whitespace-nowrap">
|
||||||
|
{e.submittedBy ?? "—"}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { formatDistanceToNowStrict } from "date-fns";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { DELIVERY_STATUS_STYLES } from "@/app/(dashboard)/pipeline/status-colors";
|
||||||
|
import type { DeliverySummary } from "@/lib/dashboard/ops";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The last few packages, and whether any of them went wrong.
|
||||||
|
*
|
||||||
|
* A failed build is otherwise silent — the exports stay READY_FOR_DELIVERY and
|
||||||
|
* nothing reaches the delivery volume, but no one finds out until the client
|
||||||
|
* asks where the shots are.
|
||||||
|
*/
|
||||||
|
export function RecentDeliveries({ deliveries }: { deliveries: DeliverySummary[] }) {
|
||||||
|
const problems = deliveries.filter((d) => d.status === "FAILED" || d.stuck).length;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-zinc-800 bg-card overflow-hidden">
|
||||||
|
<div className="flex items-center justify-between gap-3 border-b border-zinc-800/60 px-4 py-3">
|
||||||
|
<h3 className="text-sm font-semibold text-white">
|
||||||
|
Recent packages
|
||||||
|
{problems > 0 && (
|
||||||
|
<span className="ml-2 text-xs font-normal text-red-400">
|
||||||
|
{problems} need{problems === 1 ? "s" : ""} attention
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</h3>
|
||||||
|
<Link href="/pipeline/deliveries" className="text-xs text-zinc-400 hover:text-amber-400">
|
||||||
|
All deliveries →
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{deliveries.length === 0 ? (
|
||||||
|
<p className="px-4 py-8 text-center text-sm text-zinc-500">No packages built yet.</p>
|
||||||
|
) : (
|
||||||
|
deliveries.map((d) => (
|
||||||
|
<Link
|
||||||
|
key={d.id}
|
||||||
|
href="/pipeline/deliveries"
|
||||||
|
className="flex items-center gap-3 border-b border-zinc-800/60 px-4 py-2.5 last:border-b-0 hover:bg-zinc-900/40"
|
||||||
|
>
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<div className="truncate text-[13px] text-white">
|
||||||
|
<span className="font-mono font-medium">#{d.packageNumber}</span>{" "}
|
||||||
|
<span className="text-zinc-500">
|
||||||
|
{d.projectCode}
|
||||||
|
{d.episode ? ` · ${d.episode}` : ""}
|
||||||
|
{d.kind === "MOV_REVIEW" ? " · review" : ""}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="truncate text-xs text-zinc-500" title={d.errorMessage ?? undefined}>
|
||||||
|
{d.status === "FAILED" && d.errorMessage
|
||||||
|
? d.errorMessage
|
||||||
|
: `${d.itemCount} shot${d.itemCount === 1 ? "" : "s"} · ${d.atLabel} ${formatDistanceToNowStrict(d.at)} ago`}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"shrink-0 rounded-full border px-2 py-0.5 text-xs whitespace-nowrap",
|
||||||
|
// A build that never finished reads as a problem, not as work
|
||||||
|
// still in progress.
|
||||||
|
d.stuck
|
||||||
|
? "bg-red-500/15 text-red-400 border-red-500/30"
|
||||||
|
: DELIVERY_STATUS_STYLES[d.status] ?? "bg-zinc-500/15 text-zinc-300 border-zinc-500/30"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{d.stuck ? "STUCK" : d.status}
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
"use client";
|
import Link from "next/link";
|
||||||
|
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import {
|
import {
|
||||||
Clock,
|
AlertTriangle,
|
||||||
AlertCircle,
|
ClipboardCheck,
|
||||||
CheckCircle2,
|
PackageCheck,
|
||||||
XCircle,
|
Eye,
|
||||||
TrendingUp,
|
TrendingUp,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import type { DashboardStats } from "@/types";
|
import type { DashboardStats } from "@/types";
|
||||||
@@ -15,47 +14,54 @@ interface StatsCardsProps {
|
|||||||
stats: DashboardStats;
|
stats: DashboardStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Five numbers that can go down. Each one links to the page that lists what it
|
||||||
|
* counts — a figure with no way through to the rows behind it is wallpaper.
|
||||||
|
*/
|
||||||
export function StatsCards({ stats }: StatsCardsProps) {
|
export function StatsCards({ stats }: StatsCardsProps) {
|
||||||
const cards = [
|
const cards = [
|
||||||
{
|
{
|
||||||
label: "Awaiting Review",
|
label: "Blocked",
|
||||||
value: stats.awaitingReview,
|
value: stats.blocked,
|
||||||
icon: Clock,
|
href: "#blocked",
|
||||||
color: "text-amber-400",
|
icon: AlertTriangle,
|
||||||
bg: "bg-amber-500/10",
|
|
||||||
ring: "ring-amber-500/20",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Needs Revisions",
|
|
||||||
value: stats.needsRevisions,
|
|
||||||
icon: AlertCircle,
|
|
||||||
color: "text-orange-400",
|
|
||||||
bg: "bg-orange-500/10",
|
|
||||||
ring: "ring-orange-500/20",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Approved",
|
|
||||||
value: stats.approved,
|
|
||||||
icon: CheckCircle2,
|
|
||||||
color: "text-emerald-400",
|
|
||||||
bg: "bg-emerald-500/10",
|
|
||||||
ring: "ring-emerald-500/20",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Overdue Tasks",
|
|
||||||
value: stats.tasksOverdue ?? stats.overdue,
|
|
||||||
icon: XCircle,
|
|
||||||
color: "text-red-400",
|
color: "text-red-400",
|
||||||
bg: "bg-red-500/10",
|
bg: "bg-red-500/10",
|
||||||
ring: "ring-red-500/20",
|
// The only card that earns emphasis when it is non-zero: everything else
|
||||||
|
// here is a queue depth, this one is work that has stopped.
|
||||||
|
emphasise: stats.blocked > 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Active Projects",
|
label: "In QC",
|
||||||
value: stats.activeProjects,
|
value: stats.inQc,
|
||||||
icon: TrendingUp,
|
href: "/pipeline?status=READY_FOR_QC",
|
||||||
|
icon: ClipboardCheck,
|
||||||
|
color: "text-amber-400",
|
||||||
|
bg: "bg-amber-500/10",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Ready to deliver",
|
||||||
|
value: stats.readyToDeliver,
|
||||||
|
href: "/pipeline/deliveries",
|
||||||
|
icon: PackageCheck,
|
||||||
|
color: "text-green-400",
|
||||||
|
bg: "bg-green-500/10",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "With the client",
|
||||||
|
value: stats.awaitingClientReview,
|
||||||
|
href: "/playlist",
|
||||||
|
icon: Eye,
|
||||||
color: "text-blue-400",
|
color: "text-blue-400",
|
||||||
bg: "bg-blue-500/10",
|
bg: "bg-blue-500/10",
|
||||||
ring: "ring-blue-500/20",
|
},
|
||||||
|
{
|
||||||
|
label: "Active projects",
|
||||||
|
value: stats.activeProjects,
|
||||||
|
href: "/projects",
|
||||||
|
icon: TrendingUp,
|
||||||
|
color: "text-zinc-400",
|
||||||
|
bg: "bg-zinc-500/10",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -64,19 +70,31 @@ export function StatsCards({ stats }: StatsCardsProps) {
|
|||||||
{cards.map((card) => {
|
{cards.map((card) => {
|
||||||
const Icon = card.icon;
|
const Icon = card.icon;
|
||||||
return (
|
return (
|
||||||
<Card key={card.label}>
|
<Link key={card.label} href={card.href} className="group rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500">
|
||||||
<CardContent className="p-4">
|
<Card
|
||||||
<div className="flex items-center justify-between mb-3">
|
className={cn(
|
||||||
<div className={cn("p-2 rounded-md", card.bg)}>
|
"h-full transition-colors group-hover:border-zinc-700",
|
||||||
<Icon className={cn("h-4 w-4", card.color)} />
|
card.emphasise && "border-red-500/40"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<CardContent className="p-4">
|
||||||
|
<div className="flex items-center justify-between mb-3">
|
||||||
|
<div className={cn("p-2 rounded-md", card.bg)}>
|
||||||
|
<Icon className={cn("h-4 w-4", card.color)} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<p
|
||||||
<p className="text-3xl font-bold text-white">
|
className={cn(
|
||||||
{card.value}
|
"text-3xl font-bold tabular-nums",
|
||||||
</p>
|
card.emphasise ? "text-red-400" : "text-white"
|
||||||
<p className="text-sm text-zinc-400 mt-0.5">{card.label}</p>
|
)}
|
||||||
</CardContent>
|
>
|
||||||
</Card>
|
{card.value}
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-zinc-400 mt-0.5">{card.label}</p>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</Link>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import type { WhoseCourt as WhoseCourtData } from "@/lib/dashboard/ops";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which waits are the client's and which are ours.
|
||||||
|
*
|
||||||
|
* Two numbers rather than one, because they call for opposite responses: a
|
||||||
|
* version unanswered for a fortnight is a phone call, while notes nobody has
|
||||||
|
* picked up is a scheduling problem.
|
||||||
|
*/
|
||||||
|
export function WhoseCourt({ court }: { court: WhoseCourtData }) {
|
||||||
|
return (
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 rounded-lg border border-zinc-800 bg-card overflow-hidden">
|
||||||
|
<Side
|
||||||
|
title="Waiting on the client"
|
||||||
|
subtitle="Sent for review, no verdict yet"
|
||||||
|
side={court.client}
|
||||||
|
empty="Nothing is with the client."
|
||||||
|
className="border-b border-zinc-800/60 sm:border-b-0 sm:border-r"
|
||||||
|
/>
|
||||||
|
<Side
|
||||||
|
title="Waiting on us"
|
||||||
|
subtitle="Notes in, still unresolved"
|
||||||
|
side={court.us}
|
||||||
|
empty="No open notes."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Side({
|
||||||
|
title,
|
||||||
|
subtitle,
|
||||||
|
side,
|
||||||
|
empty,
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
title: string;
|
||||||
|
subtitle: string;
|
||||||
|
side: WhoseCourtData["client"];
|
||||||
|
empty: string;
|
||||||
|
className?: string;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className={`px-4 py-3 ${className ?? ""}`}>
|
||||||
|
<h4 className="text-xs font-semibold text-white">{title}</h4>
|
||||||
|
<p className="text-[11px] text-zinc-500">{subtitle}</p>
|
||||||
|
<b className="mt-2 mb-2 block font-mono text-2xl font-bold leading-none tabular-nums text-white">
|
||||||
|
{side.count}
|
||||||
|
</b>
|
||||||
|
{side.items.length === 0 ? (
|
||||||
|
<p className="text-xs text-zinc-500">{empty}</p>
|
||||||
|
) : (
|
||||||
|
<ul className="flex flex-col gap-1.5">
|
||||||
|
{side.items.map((item) => (
|
||||||
|
<li key={item.id} className="flex items-baseline justify-between gap-3 text-xs">
|
||||||
|
<Link
|
||||||
|
href={item.href}
|
||||||
|
className="truncate font-mono text-[11.5px] text-zinc-200 hover:text-amber-400"
|
||||||
|
>
|
||||||
|
{item.shotCode}
|
||||||
|
</Link>
|
||||||
|
<span className="shrink-0 tabular-nums text-zinc-500">{item.label}</span>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import { describe, it, expect } from "vitest";
|
||||||
|
import { compareVersions, projectPace } from "./ops";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The countdown's whole job is to say "you are not going to make it" early
|
||||||
|
* enough to do something about it, so the arithmetic behind that sentence is
|
||||||
|
* worth pinning down.
|
||||||
|
*/
|
||||||
|
describe("projectPace", () => {
|
||||||
|
it("calls it behind when the trailing rate overruns the date", () => {
|
||||||
|
// 29 shots to go, a fortnight left, 8 delivered last week: 1.14/day
|
||||||
|
// against the 2.07/day needed, projecting 25.4 days of work — 11.4 days
|
||||||
|
// past the date, rounded up to a whole day late.
|
||||||
|
const pace = projectPace(29, 14, 8);
|
||||||
|
expect(pace.verdict).toBe("behind");
|
||||||
|
expect(pace.requiredPerDay).toBeCloseTo(2.07, 2);
|
||||||
|
expect(pace.actualPerDay).toBeCloseTo(1.14, 2);
|
||||||
|
expect(pace.daysBehind).toBe(12);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("calls a rate that only just lands tight rather than fine", () => {
|
||||||
|
// Finishing on the last available day leaves no room for a QC failure.
|
||||||
|
expect(projectPace(10, 10, 7).verdict).toBe("tight");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is on track with real slack", () => {
|
||||||
|
const pace = projectPace(5, 30, 7);
|
||||||
|
expect(pace.verdict).toBe("ahead");
|
||||||
|
expect(pace.daysBehind).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("separates a stall from being merely slow", () => {
|
||||||
|
// Nothing shipped in a week is not a slow rate, it is no rate at all —
|
||||||
|
// dividing by it would project infinity.
|
||||||
|
const pace = projectPace(12, 20, 0);
|
||||||
|
expect(pace.verdict).toBe("stalled");
|
||||||
|
expect(pace.daysBehind).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports how far past the date an unfinished episode is", () => {
|
||||||
|
const pace = projectPace(3, -5, 4);
|
||||||
|
expect(pace.verdict).toBe("overdue");
|
||||||
|
expect(pace.daysBehind).toBe(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is complete once nothing is left, whatever the rate", () => {
|
||||||
|
expect(projectPace(0, 3, 0).verdict).toBe("complete");
|
||||||
|
expect(projectPace(0, 3, 0).requiredPerDay).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not divide by zero on the due date itself", () => {
|
||||||
|
// daysLeft 0 means "today": the work still has to be quoted per day.
|
||||||
|
expect(projectPace(4, 0, 7).requiredPerDay).toBe(4);
|
||||||
|
expect(Number.isFinite(projectPace(4, 0, 7).requiredPerDay)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The farm strip flags machines running an older worker than the newest one
|
||||||
|
* out there, which is only as reliable as this comparison: a plain string
|
||||||
|
* compare ranks "1.10.0" below "1.9.0" and would quietly stop reporting drift
|
||||||
|
* on the day the minor version reaches double digits.
|
||||||
|
*/
|
||||||
|
describe("compareVersions", () => {
|
||||||
|
it("orders by numeric component, not lexically", () => {
|
||||||
|
expect(compareVersions("1.10.0", "1.9.0")).toBeGreaterThan(0);
|
||||||
|
expect(compareVersions("1.9.0", "1.10.0")).toBeLessThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("ignores the build stamp publish.ps1 appends", () => {
|
||||||
|
// The exe reports "1.6.1+fe420b9"; two machines on the same release built
|
||||||
|
// from different commits are not drifting.
|
||||||
|
expect(compareVersions("1.6.1+fe420b9", "1.6.1")).toBe(0);
|
||||||
|
expect(compareVersions("1.6.1+fe420b9", "1.6.0+2a88880")).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("treats a missing component as zero", () => {
|
||||||
|
expect(compareVersions("1.6", "1.6.0")).toBe(0);
|
||||||
|
expect(compareVersions("1.6", "1.6.1")).toBeLessThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is transitive enough to pick a maximum", () => {
|
||||||
|
const versions = ["1.5.2", "1.6.1", "1.6.0", "1.10.0"];
|
||||||
|
const latest = versions.reduce((a, b) => (compareVersions(a, b) >= 0 ? a : b));
|
||||||
|
expect(latest).toBe("1.10.0");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,750 @@
|
|||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { getConfigNumber } from "@/lib/render-pipeline/config";
|
||||||
|
import { listMachines } from "@/lib/render-pipeline/machines";
|
||||||
|
import type { ExportStatus, Prisma } from "@prisma/client";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data for the operations dashboard.
|
||||||
|
*
|
||||||
|
* Everything here is derived from state the pipeline maintains on its own —
|
||||||
|
* export transitions, validation results, QC reviews, worker heartbeats — and
|
||||||
|
* never from a field a human has to remember to fill in. The dashboard this
|
||||||
|
* replaced counted `Task.dueDate`, which nothing in the pipeline writes, so
|
||||||
|
* its headline numbers were structurally always zero.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Terminal-until-someone-acts: these never move on their own. */
|
||||||
|
const FAILED_STATUSES: ExportStatus[] = [
|
||||||
|
"RENDER_FAILED",
|
||||||
|
"VALIDATION_FAILED",
|
||||||
|
"PREVIEW_FAILED",
|
||||||
|
"QC_FAILED",
|
||||||
|
];
|
||||||
|
|
||||||
|
/** In flight: fine until they stop progressing, then they are stuck. */
|
||||||
|
const IN_FLIGHT_STATUSES: ExportStatus[] = [
|
||||||
|
"QUEUED",
|
||||||
|
"RENDERING",
|
||||||
|
"VALIDATING",
|
||||||
|
"GENERATING_PREVIEW",
|
||||||
|
];
|
||||||
|
|
||||||
|
export type BlockedSeverity = "critical" | "warning";
|
||||||
|
|
||||||
|
export interface BlockedExport {
|
||||||
|
exportId: string;
|
||||||
|
shotId: string;
|
||||||
|
shotCode: string;
|
||||||
|
versionString: string;
|
||||||
|
projectCode: string;
|
||||||
|
episode: string | null;
|
||||||
|
status: ExportStatus;
|
||||||
|
severity: BlockedSeverity;
|
||||||
|
/** When it entered the status it is stuck in. */
|
||||||
|
since: Date;
|
||||||
|
/** What a human has to do something about, in one line. */
|
||||||
|
reason: string;
|
||||||
|
artistName: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Everything that has stopped moving and needs a person.
|
||||||
|
*
|
||||||
|
* Two kinds: exports in a failed state (which stay there forever — nothing
|
||||||
|
* retries a VALIDATION_FAILED on its own), and exports sitting in a live state
|
||||||
|
* far longer than that state should take, which is how a dead worker or a
|
||||||
|
* forgotten QC pass shows up. A failed export is currently only visible if
|
||||||
|
* someone thinks to open the render queue and filter for it.
|
||||||
|
*/
|
||||||
|
export async function getBlockedExports(
|
||||||
|
opts: { artistId?: string; limit?: number } = {}
|
||||||
|
): Promise<BlockedExport[]> {
|
||||||
|
const { artistId, limit = 25 } = opts;
|
||||||
|
const [qcStaleHours, stalledHours] = await Promise.all([
|
||||||
|
getConfigNumber("dashboard.qcStaleHours"),
|
||||||
|
getConfigNumber("dashboard.stalledJobHours"),
|
||||||
|
]);
|
||||||
|
const now = Date.now();
|
||||||
|
const qcCutoff = new Date(now - qcStaleHours * 3600_000);
|
||||||
|
const stalledCutoff = new Date(now - stalledHours * 3600_000);
|
||||||
|
|
||||||
|
const rows = await db.export.findMany({
|
||||||
|
where: {
|
||||||
|
// Finished shows would otherwise fill the list with failures nobody
|
||||||
|
// intends to fix. Export carries a projectId but no project relation, so
|
||||||
|
// the scope is reached through the shot.
|
||||||
|
shot: {
|
||||||
|
project: { status: { in: ["ACTIVE", "ON_HOLD"] } },
|
||||||
|
// An artist's dashboard shows the failures that are theirs to fix.
|
||||||
|
...(artistId ? { artistId } : {}),
|
||||||
|
},
|
||||||
|
OR: [
|
||||||
|
{ status: { in: FAILED_STATUSES } },
|
||||||
|
{ status: "READY_FOR_QC", statusChangedAt: { lt: qcCutoff } },
|
||||||
|
{ status: { in: IN_FLIGHT_STATUSES }, statusChangedAt: { lt: stalledCutoff } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
orderBy: { statusChangedAt: "asc" },
|
||||||
|
take: limit,
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
shotId: true,
|
||||||
|
versionString: true,
|
||||||
|
status: true,
|
||||||
|
statusChangedAt: true,
|
||||||
|
shot: {
|
||||||
|
select: {
|
||||||
|
shotCode: true,
|
||||||
|
episode: true,
|
||||||
|
artist: { select: { name: true, email: true } },
|
||||||
|
project: { select: { code: true } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Only the failures matter for the reason line, and only a couple of
|
||||||
|
// them: the point is to say what to look at, not to reproduce the
|
||||||
|
// validation report.
|
||||||
|
validations: {
|
||||||
|
where: { status: "FAIL" },
|
||||||
|
orderBy: { createdAt: "desc" },
|
||||||
|
take: 3,
|
||||||
|
select: { checkName: true, expected: true, actual: true, message: true },
|
||||||
|
},
|
||||||
|
qcReviews: {
|
||||||
|
orderBy: { createdAt: "desc" },
|
||||||
|
take: 1,
|
||||||
|
select: { result: true, notes: true, reviewerName: true },
|
||||||
|
},
|
||||||
|
renderJobs: {
|
||||||
|
orderBy: { createdAt: "desc" },
|
||||||
|
take: 1,
|
||||||
|
select: {
|
||||||
|
errorMessage: true,
|
||||||
|
status: true,
|
||||||
|
attempt: true,
|
||||||
|
maxAttempts: true,
|
||||||
|
machine: { select: { name: true } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const blocked = rows.map((row): BlockedExport => {
|
||||||
|
const job = row.renderJobs[0];
|
||||||
|
const qc = row.qcReviews[0];
|
||||||
|
let reason: string;
|
||||||
|
|
||||||
|
switch (row.status) {
|
||||||
|
case "VALIDATION_FAILED": {
|
||||||
|
const first = row.validations[0];
|
||||||
|
const extra = row.validations.length > 1 ? ` (+${row.validations.length - 1} more)` : "";
|
||||||
|
reason = first
|
||||||
|
? `${first.checkName} — ${first.message ?? `expected ${first.expected ?? "?"}, got ${first.actual ?? "?"}`}${extra}`
|
||||||
|
: "Validation failed";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "QC_FAILED":
|
||||||
|
reason = qc?.notes?.trim()
|
||||||
|
? `${qc.notes.trim()}${qc.reviewerName ? ` — ${qc.reviewerName}` : ""}`
|
||||||
|
: "Failed technical QC";
|
||||||
|
break;
|
||||||
|
case "RENDER_FAILED":
|
||||||
|
case "PREVIEW_FAILED":
|
||||||
|
reason =
|
||||||
|
job?.errorMessage?.trim() ||
|
||||||
|
(row.status === "RENDER_FAILED" ? "Render failed" : "Preview build failed");
|
||||||
|
if (job && job.attempt >= job.maxAttempts) reason += ` (attempt ${job.attempt}/${job.maxAttempts})`;
|
||||||
|
break;
|
||||||
|
case "READY_FOR_QC":
|
||||||
|
reason = "Waiting on a QC pass";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Still nominally in flight, but past the point where that is normal.
|
||||||
|
reason = job?.machine?.name
|
||||||
|
? `No progress since claim on ${job.machine.name}`
|
||||||
|
: "Queued with no machine picking it up";
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
exportId: row.id,
|
||||||
|
shotId: row.shotId,
|
||||||
|
shotCode: row.shot.shotCode,
|
||||||
|
versionString: row.versionString,
|
||||||
|
projectCode: row.shot.project.code,
|
||||||
|
episode: row.shot.episode,
|
||||||
|
status: row.status,
|
||||||
|
severity: FAILED_STATUSES.includes(row.status) ? "critical" : "warning",
|
||||||
|
since: row.statusChangedAt,
|
||||||
|
reason,
|
||||||
|
artistName: row.shot.artist?.name ?? row.shot.artist?.email ?? null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Failures first, then whatever has been waiting longest. Both orderings
|
||||||
|
// matter: severity decides what to fix, age decides what to fix first.
|
||||||
|
return blocked.sort((a, b) => {
|
||||||
|
if (a.severity !== b.severity) return a.severity === "critical" ? -1 : 1;
|
||||||
|
return a.since.getTime() - b.since.getTime();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CountdownVerdict = "complete" | "overdue" | "stalled" | "behind" | "tight" | "ahead";
|
||||||
|
|
||||||
|
export interface EpisodeCountdown {
|
||||||
|
projectId: string;
|
||||||
|
projectCode: string;
|
||||||
|
projectName: string;
|
||||||
|
/** Null on a standard (non-episodic) show, which has one date of its own. */
|
||||||
|
episode: string | null;
|
||||||
|
dueDate: Date;
|
||||||
|
/** Calendar days to the due date; negative once it has passed. */
|
||||||
|
daysLeft: number;
|
||||||
|
total: number;
|
||||||
|
delivered: number;
|
||||||
|
inQc: number;
|
||||||
|
inProgress: number;
|
||||||
|
notStarted: number;
|
||||||
|
/** Shots per day still needed to land the rest by the due date. */
|
||||||
|
requiredPerDay: number;
|
||||||
|
/** Shots per day actually delivered over the last week. */
|
||||||
|
actualPerDay: number;
|
||||||
|
verdict: CountdownVerdict;
|
||||||
|
/**
|
||||||
|
* How late this is: the days the current rate overruns by when `verdict` is
|
||||||
|
* "behind", or the days the date has already passed when it is "overdue".
|
||||||
|
*/
|
||||||
|
daysBehind: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DAY_MS = 86_400_000;
|
||||||
|
/** Shots past QC but not yet in a delivered package. */
|
||||||
|
const POST_QC_STATUSES: ExportStatus[] = ["READY_FOR_QC", "READY_FOR_DELIVERY", "PACKAGED"];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns "23 shots left, 14 days, 8 delivered last week" into a verdict.
|
||||||
|
*
|
||||||
|
* Kept free of the database so the arithmetic that decides whether a producer
|
||||||
|
* panics can be tested directly. The trailing week is the rate we have
|
||||||
|
* evidence for; anything else is a hope. A run that only just lands on the due
|
||||||
|
* date is reported as tight rather than fine — finishing on the last available
|
||||||
|
* day is luck, not schedule.
|
||||||
|
*/
|
||||||
|
export function projectPace(
|
||||||
|
remaining: number,
|
||||||
|
daysLeft: number,
|
||||||
|
deliveredThisWeek: number
|
||||||
|
): Pick<EpisodeCountdown, "requiredPerDay" | "actualPerDay" | "verdict" | "daysBehind"> {
|
||||||
|
const actualPerDay = deliveredThisWeek / 7;
|
||||||
|
const requiredPerDay = remaining <= 0 ? 0 : remaining / Math.max(daysLeft, 1);
|
||||||
|
|
||||||
|
if (remaining <= 0) {
|
||||||
|
return { requiredPerDay, actualPerDay, verdict: "complete", daysBehind: null };
|
||||||
|
}
|
||||||
|
if (daysLeft < 0) {
|
||||||
|
return { requiredPerDay, actualPerDay, verdict: "overdue", daysBehind: -daysLeft };
|
||||||
|
}
|
||||||
|
if (actualPerDay === 0) {
|
||||||
|
return { requiredPerDay, actualPerDay, verdict: "stalled", daysBehind: null };
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectedDays = remaining / actualPerDay;
|
||||||
|
if (projectedDays > daysLeft) {
|
||||||
|
return {
|
||||||
|
requiredPerDay,
|
||||||
|
actualPerDay,
|
||||||
|
verdict: "behind",
|
||||||
|
daysBehind: Math.ceil(projectedDays - daysLeft),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
requiredPerDay,
|
||||||
|
actualPerDay,
|
||||||
|
verdict: projectedDays > daysLeft * 0.9 ? "tight" : "ahead",
|
||||||
|
daysBehind: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are we going to make the date, per episode?
|
||||||
|
*
|
||||||
|
* A shot counts as delivered when it appears in a package that has actually
|
||||||
|
* gone out — a DeliveryItem in a DELIVERED EXR_DELIVERY package. Shot.status
|
||||||
|
* is deliberately not the measure: it says where the work is, not whether the
|
||||||
|
* client has the frames, and a review package (MOV_REVIEW) ships nothing.
|
||||||
|
*
|
||||||
|
* The run rate compares what is left per remaining day against what the studio
|
||||||
|
* actually managed per day over the last week, which is the only honest way to
|
||||||
|
* turn "23 shots to go" into "you are not going to make it".
|
||||||
|
*/
|
||||||
|
export async function getDeliveryCountdown(limit = 6): Promise<EpisodeCountdown[]> {
|
||||||
|
const projects = await db.project.findMany({
|
||||||
|
where: { status: "ACTIVE" },
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
code: true,
|
||||||
|
name: true,
|
||||||
|
dueDate: true,
|
||||||
|
projectType: true,
|
||||||
|
episodeDueDates: { select: { episode: true, dueDate: true } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (projects.length === 0) return [];
|
||||||
|
|
||||||
|
const projectIds = projects.map((p) => p.id);
|
||||||
|
const weekAgo = new Date(Date.now() - 7 * DAY_MS);
|
||||||
|
|
||||||
|
const [shots, postQc, deliveredItems] = await Promise.all([
|
||||||
|
db.shot.findMany({
|
||||||
|
where: { projectId: { in: projectIds } },
|
||||||
|
select: { id: true, projectId: true, episode: true, status: true },
|
||||||
|
}),
|
||||||
|
db.export.findMany({
|
||||||
|
where: { status: { in: POST_QC_STATUSES }, shot: { projectId: { in: projectIds } } },
|
||||||
|
select: { shotId: true },
|
||||||
|
}),
|
||||||
|
db.deliveryItem.findMany({
|
||||||
|
where: {
|
||||||
|
package: {
|
||||||
|
projectId: { in: projectIds },
|
||||||
|
kind: "EXR_DELIVERY",
|
||||||
|
status: "DELIVERED",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: { shotId: true, package: { select: { deliveredAt: true } } },
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const postQcShots = new Set(postQc.map((e) => e.shotId));
|
||||||
|
// A shot can be in several packages (a redelivery); the first one out is the
|
||||||
|
// one that counts towards the rate.
|
||||||
|
const deliveredAt = new Map<string, Date>();
|
||||||
|
for (const item of deliveredItems) {
|
||||||
|
const when = item.package.deliveredAt;
|
||||||
|
if (!when) continue;
|
||||||
|
const seen = deliveredAt.get(item.shotId);
|
||||||
|
if (!seen || when < seen) deliveredAt.set(item.shotId, when);
|
||||||
|
}
|
||||||
|
|
||||||
|
const now = Date.now();
|
||||||
|
const rows: EpisodeCountdown[] = [];
|
||||||
|
|
||||||
|
for (const project of projects) {
|
||||||
|
// Episodic shows carry a date per episode; a standard show has one date on
|
||||||
|
// the project itself, and is treated as a single unnamed target.
|
||||||
|
const targets: { episode: string | null; dueDate: Date }[] =
|
||||||
|
project.projectType === "EPISODIC"
|
||||||
|
? project.episodeDueDates.map((e) => ({ episode: e.episode, dueDate: e.dueDate }))
|
||||||
|
: project.dueDate
|
||||||
|
? [{ episode: null, dueDate: project.dueDate }]
|
||||||
|
: [];
|
||||||
|
|
||||||
|
for (const target of targets) {
|
||||||
|
const targetShots = shots.filter(
|
||||||
|
(s) =>
|
||||||
|
s.projectId === project.id &&
|
||||||
|
(target.episode === null || (s.episode ?? "") === target.episode)
|
||||||
|
);
|
||||||
|
if (targetShots.length === 0) continue;
|
||||||
|
|
||||||
|
let delivered = 0;
|
||||||
|
let inQc = 0;
|
||||||
|
let inProgress = 0;
|
||||||
|
let notStarted = 0;
|
||||||
|
let deliveredThisWeek = 0;
|
||||||
|
|
||||||
|
for (const shot of targetShots) {
|
||||||
|
const when = deliveredAt.get(shot.id);
|
||||||
|
if (when) {
|
||||||
|
delivered++;
|
||||||
|
if (when >= weekAgo) deliveredThisWeek++;
|
||||||
|
} else if (postQcShots.has(shot.id)) {
|
||||||
|
inQc++;
|
||||||
|
} else if (shot.status === "WAITING") {
|
||||||
|
notStarted++;
|
||||||
|
} else {
|
||||||
|
inProgress++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const total = targetShots.length;
|
||||||
|
const daysLeft = Math.ceil((target.dueDate.getTime() - now) / DAY_MS);
|
||||||
|
const pace = projectPace(total - delivered, daysLeft, deliveredThisWeek);
|
||||||
|
|
||||||
|
// A finished episode whose date has passed is history, not a countdown.
|
||||||
|
if (pace.verdict === "complete" && daysLeft < 0) continue;
|
||||||
|
|
||||||
|
rows.push({
|
||||||
|
projectId: project.id,
|
||||||
|
projectCode: project.code,
|
||||||
|
projectName: project.name,
|
||||||
|
episode: target.episode,
|
||||||
|
dueDate: target.dueDate,
|
||||||
|
daysLeft,
|
||||||
|
total,
|
||||||
|
delivered,
|
||||||
|
inQc,
|
||||||
|
inProgress,
|
||||||
|
notStarted,
|
||||||
|
...pace,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows.sort((a, b) => a.dueDate.getTime() - b.dueDate.getTime()).slice(0, limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OpsCounts {
|
||||||
|
blocked: number;
|
||||||
|
inQc: number;
|
||||||
|
readyToDeliver: number;
|
||||||
|
awaitingClientReview: number;
|
||||||
|
activeProjects: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The headline numbers, all scoped to live productions.
|
||||||
|
*
|
||||||
|
* The counters these replaced were unscoped and cumulative — "approved" across
|
||||||
|
* every project the studio has ever finished only ever goes up, so it never
|
||||||
|
* told anyone anything. Each of these can go down, which is what makes it
|
||||||
|
* worth looking at twice in a day.
|
||||||
|
*/
|
||||||
|
export async function getOpsCounts(artistId?: string): Promise<OpsCounts> {
|
||||||
|
// Export has a projectId column but no project relation, so live-production
|
||||||
|
// scope is reached through the shot. An artist gets their own figures, so the
|
||||||
|
// cards agree with the blocked list underneath them rather than quoting a
|
||||||
|
// studio-wide number beside a personal one.
|
||||||
|
const liveProject: Prisma.ExportWhereInput = {
|
||||||
|
shot: {
|
||||||
|
project: { status: { in: ["ACTIVE", "ON_HOLD"] } },
|
||||||
|
...(artistId ? { artistId } : {}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const [qcStaleHours, stalledHours] = await Promise.all([
|
||||||
|
getConfigNumber("dashboard.qcStaleHours"),
|
||||||
|
getConfigNumber("dashboard.stalledJobHours"),
|
||||||
|
]);
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
const [blocked, inQc, readyToDeliver, awaitingClientReview, activeProjects] = await Promise.all([
|
||||||
|
db.export.count({
|
||||||
|
where: {
|
||||||
|
...liveProject,
|
||||||
|
OR: [
|
||||||
|
{ status: { in: FAILED_STATUSES } },
|
||||||
|
{ status: "READY_FOR_QC", statusChangedAt: { lt: new Date(now - qcStaleHours * 3600_000) } },
|
||||||
|
{
|
||||||
|
status: { in: IN_FLIGHT_STATUSES },
|
||||||
|
statusChangedAt: { lt: new Date(now - stalledHours * 3600_000) },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
db.export.count({ where: { ...liveProject, status: "READY_FOR_QC" } }),
|
||||||
|
db.export.count({ where: { ...liveProject, status: "READY_FOR_DELIVERY" } }),
|
||||||
|
// Sent to the client and still unanswered — the wait that is not ours to
|
||||||
|
// end, as opposed to notes we have not acted on yet.
|
||||||
|
db.version.count({
|
||||||
|
where: {
|
||||||
|
approvalStatus: "PENDING_REVIEW",
|
||||||
|
isClientVisible: true,
|
||||||
|
isLatest: true,
|
||||||
|
shot: {
|
||||||
|
project: { status: { in: ["ACTIVE", "ON_HOLD"] } },
|
||||||
|
...(artistId ? { artistId } : {}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
db.project.count({ where: { status: "ACTIVE" } }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return { blocked, inQc, readyToDeliver, awaitingClientReview, activeProjects };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** How long an export may sit in READY_FOR_QC before the UI calls it stale. */
|
||||||
|
export function getQcStaleHours(): Promise<number> {
|
||||||
|
return getConfigNumber("dashboard.qcStaleHours");
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface QcQueueEntry {
|
||||||
|
exportId: string;
|
||||||
|
shotCode: string;
|
||||||
|
versionString: string;
|
||||||
|
projectCode: string;
|
||||||
|
episode: string | null;
|
||||||
|
since: Date;
|
||||||
|
frameStart: number;
|
||||||
|
frameEnd: number;
|
||||||
|
submittedBy: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What is waiting on a human to look at the frames.
|
||||||
|
*
|
||||||
|
* QC is the last gate before anything can be packaged, and it is the only
|
||||||
|
* stage in the pipeline that cannot drain itself — everything before it is
|
||||||
|
* worked by the farm. Depth here is the single best predictor of a delivery
|
||||||
|
* slipping, and until now it had no home outside the render queue's filter.
|
||||||
|
*/
|
||||||
|
export async function getQcQueue(limit = 8): Promise<QcQueueEntry[]> {
|
||||||
|
const rows = await db.export.findMany({
|
||||||
|
where: {
|
||||||
|
status: "READY_FOR_QC",
|
||||||
|
shot: { project: { status: { in: ["ACTIVE", "ON_HOLD"] } } },
|
||||||
|
},
|
||||||
|
orderBy: { statusChangedAt: "asc" },
|
||||||
|
take: limit,
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
versionString: true,
|
||||||
|
statusChangedAt: true,
|
||||||
|
frameStart: true,
|
||||||
|
frameEnd: true,
|
||||||
|
submittedByName: true,
|
||||||
|
shot: {
|
||||||
|
select: { shotCode: true, episode: true, project: { select: { code: true } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return rows.map((row) => ({
|
||||||
|
exportId: row.id,
|
||||||
|
shotCode: row.shot.shotCode,
|
||||||
|
versionString: row.versionString,
|
||||||
|
projectCode: row.shot.project.code,
|
||||||
|
episode: row.shot.episode,
|
||||||
|
since: row.statusChangedAt,
|
||||||
|
frameStart: row.frameStart,
|
||||||
|
frameEnd: row.frameEnd,
|
||||||
|
// Free text from the panel's config: Export keeps submittedById for the
|
||||||
|
// resolved account but carries no relation to it.
|
||||||
|
submittedBy: row.submittedByName,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DeliverySummary {
|
||||||
|
id: string;
|
||||||
|
packageNumber: number;
|
||||||
|
name: string;
|
||||||
|
projectCode: string;
|
||||||
|
episode: string;
|
||||||
|
kind: string;
|
||||||
|
status: string;
|
||||||
|
itemCount: number;
|
||||||
|
errorMessage: string | null;
|
||||||
|
/** Most recent of delivered/built/created — what the timestamp column means. */
|
||||||
|
at: Date;
|
||||||
|
atLabel: "delivered" | "built" | "created";
|
||||||
|
/** BUILDING for longer than a build plausibly takes. */
|
||||||
|
stuck: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recent packages, and whether any of them went wrong.
|
||||||
|
*
|
||||||
|
* A failed delivery build is otherwise silent: the export stays
|
||||||
|
* READY_FOR_DELIVERY, nothing is on the delivery volume, and the only trace is
|
||||||
|
* a status on a page nobody opens between deliveries.
|
||||||
|
*/
|
||||||
|
export async function getRecentDeliveries(limit = 5): Promise<DeliverySummary[]> {
|
||||||
|
const rows = await db.deliveryPackage.findMany({
|
||||||
|
where: { project: { status: { in: ["ACTIVE", "ON_HOLD"] } } },
|
||||||
|
orderBy: { createdAt: "desc" },
|
||||||
|
take: limit,
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
packageNumber: true,
|
||||||
|
name: true,
|
||||||
|
episode: true,
|
||||||
|
kind: true,
|
||||||
|
status: true,
|
||||||
|
errorMessage: true,
|
||||||
|
createdAt: true,
|
||||||
|
builtAt: true,
|
||||||
|
deliveredAt: true,
|
||||||
|
project: { select: { code: true } },
|
||||||
|
_count: { select: { items: true } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const buildStuckAfter = 2 * 3600_000;
|
||||||
|
return rows.map((row) => {
|
||||||
|
const at = row.deliveredAt ?? row.builtAt ?? row.createdAt;
|
||||||
|
return {
|
||||||
|
id: row.id,
|
||||||
|
packageNumber: row.packageNumber,
|
||||||
|
name: row.name,
|
||||||
|
projectCode: row.project.code,
|
||||||
|
episode: row.episode,
|
||||||
|
kind: row.kind,
|
||||||
|
status: row.status,
|
||||||
|
itemCount: row._count.items,
|
||||||
|
errorMessage: row.errorMessage,
|
||||||
|
at,
|
||||||
|
atLabel: row.deliveredAt ? "delivered" : row.builtAt ? "built" : "created",
|
||||||
|
// A build that never finished leaves the package sitting in BUILDING
|
||||||
|
// forever; nothing times it out.
|
||||||
|
stuck: row.status === "BUILDING" && Date.now() - row.createdAt.getTime() > buildStuckAfter,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CourtSide {
|
||||||
|
count: number;
|
||||||
|
items: { id: string; shotCode: string; label: string; href: string }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WhoseCourt {
|
||||||
|
client: CourtSide;
|
||||||
|
us: CourtSide;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which waits are ours and which are the client's.
|
||||||
|
*
|
||||||
|
* The distinction is the useful part: a version sitting unanswered for eleven
|
||||||
|
* days is a phone call, while notes nobody has actioned are a scheduling
|
||||||
|
* problem. Lumping both into "needs revisions" hid which was which.
|
||||||
|
*/
|
||||||
|
export async function getWhoseCourt(perSide = 4): Promise<WhoseCourt> {
|
||||||
|
const liveShot: Prisma.ShotWhereInput = {
|
||||||
|
project: { status: { in: ["ACTIVE", "ON_HOLD"] } },
|
||||||
|
};
|
||||||
|
|
||||||
|
const [withClient, openNotes] = await Promise.all([
|
||||||
|
db.version.findMany({
|
||||||
|
where: {
|
||||||
|
approvalStatus: "PENDING_REVIEW",
|
||||||
|
isClientVisible: true,
|
||||||
|
isLatest: true,
|
||||||
|
shot: liveShot,
|
||||||
|
},
|
||||||
|
// Longest wait first — that is the one worth chasing.
|
||||||
|
orderBy: [{ sharedAt: { sort: "asc", nulls: "last" } }, { createdAt: "asc" }],
|
||||||
|
take: perSide,
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
versionNumber: true,
|
||||||
|
sharedAt: true,
|
||||||
|
createdAt: true,
|
||||||
|
shot: { select: { id: true, shotCode: true } },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
// Unresolved notes on the version currently in play. Grouped in memory
|
||||||
|
// because the interesting unit is the shot, not the comment.
|
||||||
|
db.comment.findMany({
|
||||||
|
where: {
|
||||||
|
isResolved: false,
|
||||||
|
version: { isLatest: true, shot: liveShot },
|
||||||
|
},
|
||||||
|
select: { id: true, version: { select: { shot: { select: { id: true, shotCode: true } } } } },
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const byShot = new Map<string, { shotCode: string; count: number }>();
|
||||||
|
for (const note of openNotes) {
|
||||||
|
const shot = note.version?.shot;
|
||||||
|
if (!shot) continue;
|
||||||
|
const entry = byShot.get(shot.id) ?? { shotCode: shot.shotCode, count: 0 };
|
||||||
|
entry.count++;
|
||||||
|
byShot.set(shot.id, entry);
|
||||||
|
}
|
||||||
|
const ours = [...byShot.entries()].sort((a, b) => b[1].count - a[1].count);
|
||||||
|
|
||||||
|
const days = (from: Date) => Math.max(0, Math.floor((Date.now() - from.getTime()) / DAY_MS));
|
||||||
|
|
||||||
|
return {
|
||||||
|
client: {
|
||||||
|
count: withClient.length,
|
||||||
|
items: withClient.map((v) => ({
|
||||||
|
id: v.id,
|
||||||
|
shotCode: v.shot?.shotCode ?? "—",
|
||||||
|
label: `${days(v.sharedAt ?? v.createdAt)}d`,
|
||||||
|
href: `/review/${v.id}`,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
us: {
|
||||||
|
count: ours.length,
|
||||||
|
items: ours.slice(0, perSide).map(([shotId, entry]) => ({
|
||||||
|
id: shotId,
|
||||||
|
shotCode: entry.shotCode,
|
||||||
|
label: `${entry.count} note${entry.count === 1 ? "" : "s"}`,
|
||||||
|
href: `/shot-status`,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FarmStatus {
|
||||||
|
machines: Awaited<ReturnType<typeof listMachines>>;
|
||||||
|
online: number;
|
||||||
|
total: number;
|
||||||
|
queued: { render: number; preview: number; delivery: number; blender: number; total: number };
|
||||||
|
running: number;
|
||||||
|
/** Age of the oldest job still waiting to be claimed, in ms. */
|
||||||
|
oldestQueuedMs: number | null;
|
||||||
|
/** Highest worker version any machine reports, and who is behind it. */
|
||||||
|
latestWorkerVersion: string | null;
|
||||||
|
behindMachines: { name: string; workerVersion: string | null }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Farm health in one strip: who is up, what is waiting, and — because a
|
||||||
|
* worker's version is what decides whether it has a given fix — which
|
||||||
|
* machines are running something older than the newest one out there.
|
||||||
|
*/
|
||||||
|
export async function getFarmStatus(): Promise<FarmStatus> {
|
||||||
|
const [machines, queuedByType, running, oldest] = await Promise.all([
|
||||||
|
listMachines(),
|
||||||
|
db.renderJob.groupBy({ by: ["type"], where: { status: "QUEUED" }, _count: { _all: true } }),
|
||||||
|
db.renderJob.count({ where: { status: { in: ["CLAIMED", "RUNNING"] } } }),
|
||||||
|
db.renderJob.findFirst({
|
||||||
|
where: { status: "QUEUED" },
|
||||||
|
orderBy: { createdAt: "asc" },
|
||||||
|
select: { createdAt: true },
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const countOf = (type: string) =>
|
||||||
|
queuedByType.find((q) => q.type === type)?._count._all ?? 0;
|
||||||
|
|
||||||
|
const versions = machines
|
||||||
|
.map((m) => m.workerVersion)
|
||||||
|
.filter((v): v is string => Boolean(v));
|
||||||
|
const latest = versions.length ? versions.reduce((a, b) => (compareVersions(a, b) >= 0 ? a : b)) : null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
machines,
|
||||||
|
online: machines.filter((m) => m.status === "ONLINE").length,
|
||||||
|
total: machines.length,
|
||||||
|
queued: {
|
||||||
|
render: countOf("AE_RENDER"),
|
||||||
|
preview: countOf("PREVIEW_ONLY"),
|
||||||
|
delivery: countOf("DELIVERY_BUILD"),
|
||||||
|
blender: countOf("BLENDER_RENDER"),
|
||||||
|
total: queuedByType.reduce((sum, q) => sum + q._count._all, 0),
|
||||||
|
},
|
||||||
|
running,
|
||||||
|
oldestQueuedMs: oldest ? Date.now() - oldest.createdAt.getTime() : null,
|
||||||
|
latestWorkerVersion: latest,
|
||||||
|
behindMachines: latest
|
||||||
|
? machines
|
||||||
|
.filter((m) => m.workerVersion !== latest)
|
||||||
|
.map((m) => ({ name: m.name, workerVersion: m.workerVersion }))
|
||||||
|
: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares "1.6.1+fe420b9" style versions numerically, ignoring the build
|
||||||
|
* stamp publish.ps1 appends. A string compare would rank 1.10.0 below 1.9.0.
|
||||||
|
*/
|
||||||
|
export function compareVersions(a: string, b: string): number {
|
||||||
|
const parts = (v: string) =>
|
||||||
|
v.split("+")[0].split(".").map((n) => Number.parseInt(n, 10) || 0);
|
||||||
|
const [pa, pb] = [parts(a), parts(b)];
|
||||||
|
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
||||||
|
const diff = (pa[i] ?? 0) - (pb[i] ?? 0);
|
||||||
|
if (diff !== 0) return diff;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -48,6 +48,13 @@ export const PIPELINE_CONFIG_DEFAULTS = {
|
|||||||
// names as a warning, so it is a config fix rather than a code change.
|
// names as a warning, so it is a config fix rather than a code change.
|
||||||
"preview.slateScopeProp": "Scope",
|
"preview.slateScopeProp": "Scope",
|
||||||
"preview.slateSubmissionProp": "Notes",
|
"preview.slateSubmissionProp": "Notes",
|
||||||
|
/**
|
||||||
|
* When the dashboard starts calling something stuck. An export waiting on QC
|
||||||
|
* is normal for a day and suspicious after two; an export in a live render
|
||||||
|
* state has either progressed or died long before four hours are up.
|
||||||
|
*/
|
||||||
|
"dashboard.qcStaleHours": 48,
|
||||||
|
"dashboard.stalledJobHours": 4,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type PipelineConfigKey = keyof typeof PIPELINE_CONFIG_DEFAULTS;
|
export type PipelineConfigKey = keyof typeof PIPELINE_CONFIG_DEFAULTS;
|
||||||
|
|||||||
+9
-9
@@ -276,17 +276,17 @@ export interface AssetWithDetails {
|
|||||||
|
|
||||||
// ── Dashboard Types ──────────────────────────────────────────────────────────
|
// ── Dashboard Types ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dashboard headline numbers. Every one is derived from pipeline state and
|
||||||
|
* scoped to live productions — see lib/dashboard/ops.ts. The previous shape
|
||||||
|
* carried task due/overdue counts, which read a column nothing writes.
|
||||||
|
*/
|
||||||
export interface DashboardStats {
|
export interface DashboardStats {
|
||||||
awaitingReview: number;
|
blocked: number;
|
||||||
needsRevisions: number;
|
inQc: number;
|
||||||
approved: number;
|
readyToDeliver: number;
|
||||||
overdue: number;
|
awaitingClientReview: number;
|
||||||
activeProjects: number;
|
activeProjects: number;
|
||||||
// Task widgets
|
|
||||||
tasksDueToday: number;
|
|
||||||
tasksInReview: number;
|
|
||||||
tasksOverdue: number;
|
|
||||||
myTasksCount: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Notification Badge ────────────────────────────────────────────────────────
|
// ── Notification Badge ────────────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user