* Rename tables, add graphile workers, update types * Add dev:worker command * Update pnpm-lock.yaml * Remove sentry config import from worker.ts * Stop generating new cells in cell router get query * Generate new cells for new scenarios, variants, and experiments * Remove most error throwing from queryLLM.task.ts * Remove promptVariantId and testScenarioId from ModelOutput * Remove duplicate index from ModelOutput * Move inputHash from cell to output * Add TODO * Add todo * Show cost and time for each cell * Always show output stats if there is output * Trigger LLM outputs when scenario variables are updated * Add newlines to ends of files * Add another newline * Cascade ModelOutput deletion * Fix linting and prettier * Return instead of throwing for non-pending cell * Remove pnpm dev:worker from pnpm:dev * Update pnpm-lock.yaml
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { type ScenarioVariantCell } from "@prisma/client";
|
|
import { VStack, Text } from "@chakra-ui/react";
|
|
import { useEffect, useState } from "react";
|
|
import pluralize from "pluralize";
|
|
|
|
export const ErrorHandler = ({
|
|
cell,
|
|
refetchOutput,
|
|
}: {
|
|
cell: ScenarioVariantCell;
|
|
refetchOutput: () => void;
|
|
}) => {
|
|
const [msToWait, setMsToWait] = useState(0);
|
|
|
|
useEffect(() => {
|
|
if (!cell.retryTime) return;
|
|
|
|
const initialWaitTime = cell.retryTime.getTime() - Date.now();
|
|
const msModuloOneSecond = initialWaitTime % 1000;
|
|
let remainingTime = initialWaitTime - msModuloOneSecond;
|
|
setMsToWait(remainingTime);
|
|
|
|
let interval: NodeJS.Timeout;
|
|
const timeout = setTimeout(() => {
|
|
interval = setInterval(() => {
|
|
remainingTime -= 1000;
|
|
setMsToWait(remainingTime);
|
|
|
|
if (remainingTime <= 0) {
|
|
clearInterval(interval);
|
|
}
|
|
}, 1000);
|
|
}, msModuloOneSecond);
|
|
|
|
return () => {
|
|
clearInterval(interval);
|
|
clearTimeout(timeout);
|
|
};
|
|
}, [cell.retryTime, cell.statusCode, setMsToWait, refetchOutput]);
|
|
|
|
return (
|
|
<VStack w="full">
|
|
<Text color="red.600" wordBreak="break-word">
|
|
{cell.errorMessage}
|
|
</Text>
|
|
{msToWait > 0 && (
|
|
<Text color="red.600" fontSize="sm">
|
|
Retrying in {pluralize("second", Math.ceil(msToWait / 1000), true)}...
|
|
</Text>
|
|
)}
|
|
</VStack>
|
|
);
|
|
};
|