import { AlertBlock } from "@/components/shared/alert-block"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; import React, { useEffect } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import { InfoIcon } from "lucide-react"; const addResourcesApplication = z.object({ memoryReservation: z.number().nullable().optional(), cpuLimit: z.number().nullable().optional(), memoryLimit: z.number().nullable().optional(), cpuReservation: z.number().nullable().optional(), }); interface Props { applicationId: string; } type AddResourcesApplication = z.infer; export const ShowApplicationResources = ({ applicationId }: Props) => { const { data, refetch } = api.application.one.useQuery( { applicationId, }, { enabled: !!applicationId }, ); const { mutateAsync, isLoading } = api.application.update.useMutation(); const form = useForm({ defaultValues: {}, resolver: zodResolver(addResourcesApplication), }); useEffect(() => { if (data) { form.reset({ cpuLimit: data?.cpuLimit || undefined, cpuReservation: data?.cpuReservation || undefined, memoryLimit: data?.memoryLimit || undefined, memoryReservation: data?.memoryReservation || undefined, }); } }, [data, form, form.reset]); const onSubmit = async (formData: AddResourcesApplication) => { await mutateAsync({ applicationId, cpuLimit: formData.cpuLimit || null, cpuReservation: formData.cpuReservation || null, memoryLimit: formData.memoryLimit || null, memoryReservation: formData.memoryReservation || null, }) .then(async () => { toast.success("Resources Updated"); await refetch(); }) .catch(() => { toast.error("Error updating the resources"); }); }; return ( Resources If you want to decrease or increase the resources to a specific. application or database Please remember to click Redeploy after modify the resources to apply the changes.
(
Memory Reservation

Memory soft limit in bytes. Example: 256MB = 268435456 bytes

{ const value = e.target.value; if (value === "") { field.onChange(null); } else { const number = Number.parseInt(value, 10); if (!Number.isNaN(number)) { field.onChange(number); } } }} />
)} /> { return (
Memory Limit

Memory hard limit in bytes. Example: 1GB = 1073741824 bytes

{ const value = e.target.value; if (value === "") { field.onChange(null); } else { const number = Number.parseInt(value, 10); if (!Number.isNaN(number)) { field.onChange(number); } } }} />
); }} /> { return (
CPU Limit

CPU quota in units of 10^-9 CPUs. Example: 2 CPUs = 2000000000

{ const value = e.target.value; if (value === "") { field.onChange(null); } else { const number = Number.parseInt(value, 10); if (!Number.isNaN(number)) { field.onChange(number); } } }} />
); }} /> { return (
CPU Reservation

CPU shares (relative weight). Example: 1 CPU = 1000000000

{ const value = e.target.value; if (value === "") { field.onChange(null); } else { const number = Number.parseInt(value, 10); if (!Number.isNaN(number)) { field.onChange(number); } } }} />
); }} />
); };