Serverless function follow up (#9924)

- remove asynchronous serverless function build
- build serverless function synchronously instead on activate workflow
or execute
- add a loader on workflow code step test tab test button
- add a new `ServerlessFunctionSyncStatus` `BUILDING`
- add a new route to build a serverless function draft version 
- delay artificially execution to avoid UI flashing



https://github.com/user-attachments/assets/8d958d9a-ef41-4261-999e-6ea374191e33
This commit is contained in:
martmull
2025-01-31 17:12:42 +01:00
committed by GitHub
parent f47c0d45e3
commit ae62789159
28 changed files with 430 additions and 224 deletions

View File

@ -0,0 +1,13 @@
import { gql } from '@apollo/client';
import { SERVERLESS_FUNCTION_FRAGMENT } from '@/settings/serverless-functions/graphql/fragments/serverlessFunctionFragment';
export const BUILD_DRAFT_SERVERLESS_FUNCTION = gql`
${SERVERLESS_FUNCTION_FRAGMENT}
mutation BuildDraftServerlessFunction(
$input: BuildDraftServerlessFunctionInput!
) {
buildDraftServerlessFunction(input: $input) {
...ServerlessFunctionFields
}
}
`;

View File

@ -0,0 +1,29 @@
import { useApolloMetadataClient } from '@/object-metadata/hooks/useApolloMetadataClient';
import { useMutation } from '@apollo/client';
import { BUILD_DRAFT_SERVERLESS_FUNCTION } from '@/settings/serverless-functions/graphql/mutations/buildDraftServerlessFunction';
import {
BuildDraftServerlessFunctionMutation,
BuildDraftServerlessFunctionMutationVariables,
BuildDraftServerlessFunctionInput,
} from '~/generated-metadata/graphql';
export const useBuildDraftServerlessFunction = () => {
const apolloMetadataClient = useApolloMetadataClient();
const [mutate] = useMutation<
BuildDraftServerlessFunctionMutation,
BuildDraftServerlessFunctionMutationVariables
>(BUILD_DRAFT_SERVERLESS_FUNCTION, {
client: apolloMetadataClient,
});
const buildDraftServerlessFunction = async (
input: BuildDraftServerlessFunctionInput,
) => {
return await mutate({
variables: {
input,
},
});
};
return { buildDraftServerlessFunction };
};

View File

@ -25,6 +25,7 @@ export const useGetOneServerlessFunctionSourceCode = ({
input: { id, version },
},
onCompleted,
fetchPolicy: 'network-only',
});
return { code: data?.getServerlessFunctionSourceCode, loading };
};

View File

@ -6,9 +6,6 @@ import {
UpdateOneServerlessFunctionMutationVariables,
UpdateServerlessFunctionInput,
} from '~/generated-metadata/graphql';
import { useEffect, useState } from 'react';
import { FIND_ONE_SERVERLESS_FUNCTION } from '@/settings/serverless-functions/graphql/queries/findOneServerlessFunction';
import { sleep } from '~/utils/sleep';
import { getOperationName } from '@apollo/client/utilities';
import { FIND_ONE_SERVERLESS_FUNCTION_SOURCE_CODE } from '@/settings/serverless-functions/graphql/queries/findOneServerlessFunctionSourceCode';
@ -16,7 +13,6 @@ export const useUpdateOneServerlessFunction = (
serverlessFunctionId: string,
) => {
const apolloMetadataClient = useApolloMetadataClient();
const [isReady, setIsReady] = useState(false);
const [mutate] = useMutation<
UpdateOneServerlessFunctionMutation,
UpdateOneServerlessFunctionMutationVariables
@ -27,7 +23,7 @@ export const useUpdateOneServerlessFunction = (
const updateOneServerlessFunction = async (
input: Omit<UpdateServerlessFunctionInput, 'id'>,
) => {
const result = await mutate({
return await mutate({
variables: {
input: { ...input, id: serverlessFunctionId },
},
@ -35,37 +31,7 @@ export const useUpdateOneServerlessFunction = (
getOperationName(FIND_ONE_SERVERLESS_FUNCTION_SOURCE_CODE) ?? '',
],
});
setIsReady(false);
return result;
};
useEffect(() => {
let isMounted = true;
const pollFunctionStatus = async () => {
while (isMounted && !isReady) {
const { data } = await apolloMetadataClient.query({
query: FIND_ONE_SERVERLESS_FUNCTION,
variables: { input: { id: serverlessFunctionId } },
fetchPolicy: 'network-only', // Always fetch fresh data
});
const serverlessFunction = data?.findOneServerlessFunction;
if (serverlessFunction?.syncStatus === 'READY') {
setIsReady(true);
break;
}
await sleep(500);
}
};
pollFunctionStatus();
return () => {
isMounted = false; // Cleanup when the component unmounts
};
}, [serverlessFunctionId, apolloMetadataClient, isReady]);
return { updateOneServerlessFunction, isReady };
return { updateOneServerlessFunction };
};