Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useToastMutation } from '@/common/hooks/use-toast-mutation'
import { postApiV1BetaWorkloadsMutation } from '@api/@tanstack/react-query.gen'
import { getApiV1BetaWorkloadsByNameExport } from '@api/sdk.gen'
import {
getApiV1BetaWorkloadsByNameExport,
getApiV1BetaWorkloads,
} from '@api/sdk.gen'
import { getApiV1BetaWorkloadsQueryKey } from '@api/@tanstack/react-query.gen'
import { useQueryClient } from '@tanstack/react-query'
import { useMutation } from '@tanstack/react-query'
Expand All @@ -25,6 +28,31 @@ export function useMutationUpdateWorkloadGroup() {
throwOnError: true,
})

const newServerName = `${runConfig.name}-${groupName}`

// Check if server already exists (across all groups, since names must be globally unique)
const { data: existingWorkloads } = await getApiV1BetaWorkloads({
query: { all: true },
throwOnError: true,
})

console.log('[Copy Server] Checking for existing server:', {
newServerName,
existingWorkloadNames: existingWorkloads?.workloads?.map((w) => w.name),
})

const serverExists = existingWorkloads?.workloads?.some(
(w) => w.name === newServerName
)

console.log('[Copy Server] Server exists?', serverExists)

if (serverExists) {
throw new Error(
`Server "${newServerName}" already exists. Please remove the existing server first or choose a different group name.`
)
}

const secrets = (runConfig.secrets || []).map((secretStr) => {
const [secretName, target] = secretStr.split(',target=')

Expand All @@ -36,7 +64,7 @@ export function useMutationUpdateWorkloadGroup() {

const result = await createWorkload({
body: {
name: `${runConfig.name}-${groupName}`,
name: newServerName,
image: runConfig.image,
transport: runConfig.transport,
cmd_arguments: runConfig.cmd_args || [],
Expand All @@ -59,7 +87,6 @@ export function useMutationUpdateWorkloadGroup() {
},
successMsg: (variables) =>
`Server "${variables.workloadName}" copied to group "${variables.groupName}" successfully`,
errorMsg: 'Failed to copy server to group',
loadingMsg: 'Copying server to group...',
})
}
Loading