Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX]: Running queue items #18

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions apps/spu-ui/src/app/_components/queue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type { QueueItemProps } from "../../lib/types";
import { useQueue } from "../_hooks/use-queue";
import { useStatus } from "../_hooks/use-status";
import { kwargsResponseSchema } from "../../lib/schemas/acquisition";
import { api } from "../../trpc/react";
import { Dropzone } from "./dropzone";
import { EnvMenu } from "./env-menu";

Expand Down Expand Up @@ -144,12 +143,8 @@ function QueueItem({
}

export function Queue() {
const utils = api.useUtils();
const { queue } = useQueue();
const { clear } = useQueue();
const { queue, clear, start, stop } = useQueue();
const { status } = useStatus();
const start = api.queue.start.useMutation();
const stop = api.queue.stop.useMutation();

// const handleDragEnd = ({ active, over }: DragEndEvent) => {
// if (over && active.id !== over.id) {
Expand All @@ -162,33 +157,35 @@ export function Queue() {

const startQueue = useCallback(() => {
start.mutate(undefined, {
onSuccess: async () => {
await utils.queue.get.invalidate();
onSuccess: () => {
toast.success("Queue started");
},
onError: async () => {
await utils.queue.get.invalidate();
onError: () => {
toast.error("Failed to start queue");
},
});
}, [start, utils.queue.get]);
}, [start]);

const stopQueue = useCallback(() => {
stop.mutate(undefined, {
onSuccess: async () => {
await utils.queue.get.invalidate();
onSuccess: () => {
toast.success("Queue stopped");
},
onError: async () => {
await utils.queue.get.invalidate();
onError: () => {
toast.error("Failed to stop queue");
},
});
}, [stop, utils.queue.get]);
}, [stop]);

const clearQueue = useCallback(async () => {
await clear.mutateAsync();
toast.info("Queue cleared");
const clearQueue = useCallback(() => {
clear.mutate(undefined, {
onSuccess: () => {
toast.success("Queue cleared");
},
onError: () => {
toast.error("Failed to clear queue");
},
});
}, [clear]);

const handleDragEnd = ({ active, over }: DragEndEvent) => {
Expand Down Expand Up @@ -232,7 +229,8 @@ export function Queue() {
</div>
<Dropzone id="queue-dropzone">
<ScrollArea className="flex h-[calc(100vh-480px)] w-full flex-col">
{queue.data?.items.length === 0 ? (
{queue.data?.items.length === 0 &&
!queue.data.runningItem?.itemUid ? (
<p className="text-center text-muted-foreground">
Queue is empty. Drag samples here to add them to the queue.
</p>
Expand Down
14 changes: 14 additions & 0 deletions apps/spu-ui/src/app/_hooks/use-queue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,25 @@ export const useQueue = () => {
},
});

const start = api.queue.start.useMutation({
onSettled: async () => {
await utils.queue.get.invalidate();
},
});

const stop = api.queue.stop.useMutation({
onSettled: async () => {
await utils.queue.get.invalidate();
},
});

return {
queue,
add,
addBatch,
remove,
clear,
start,
stop,
};
};