Add duplicate step action (#14392)
https://github.com/user-attachments/assets/ac89440c-6f84-4d2a-b88a-da7ddfb181eb
This commit is contained in:
+1
@@ -10,4 +10,5 @@ export enum ServerlessFunctionExceptionCode {
|
||||
SERVERLESS_FUNCTION_BUILDING = 'SERVERLESS_FUNCTION_BUILDING',
|
||||
SERVERLESS_FUNCTION_CODE_UNCHANGED = 'SERVERLESS_FUNCTION_CODE_UNCHANGED',
|
||||
SERVERLESS_FUNCTION_EXECUTION_LIMIT_REACHED = 'SERVERLESS_FUNCTION_EXECUTION_LIMIT_REACHED',
|
||||
SERVERLESS_FUNCTION_CREATE_FAILED = 'SERVERLESS_FUNCTION_CREATE_FAILED',
|
||||
}
|
||||
|
||||
+52
-1
@@ -363,7 +363,7 @@ export class ServerlessFunctionService {
|
||||
});
|
||||
}
|
||||
|
||||
async usePublishedVersionAsDraft({
|
||||
async createDraftFromPublishedVersion({
|
||||
id,
|
||||
version,
|
||||
workspaceId,
|
||||
@@ -400,6 +400,57 @@ export class ServerlessFunctionService {
|
||||
});
|
||||
}
|
||||
|
||||
async duplicateServerlessFunction({
|
||||
id,
|
||||
version,
|
||||
workspaceId,
|
||||
}: {
|
||||
id: string;
|
||||
version: string;
|
||||
workspaceId: string;
|
||||
}) {
|
||||
const serverlessFunctionToDuplicate =
|
||||
await this.serverlessFunctionRepository.findOneOrFail({
|
||||
where: {
|
||||
id,
|
||||
workspaceId,
|
||||
},
|
||||
});
|
||||
|
||||
const newServerlessFunction = await this.createOneServerlessFunction(
|
||||
{
|
||||
name: serverlessFunctionToDuplicate.name,
|
||||
description: serverlessFunctionToDuplicate.description,
|
||||
timeoutSeconds: serverlessFunctionToDuplicate.timeoutSeconds,
|
||||
},
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (!isDefined(newServerlessFunction)) {
|
||||
throw new ServerlessFunctionException(
|
||||
'Failed to create new serverless function',
|
||||
ServerlessFunctionExceptionCode.SERVERLESS_FUNCTION_CREATE_FAILED,
|
||||
);
|
||||
}
|
||||
|
||||
await this.fileStorageService.copy({
|
||||
from: {
|
||||
folderPath: getServerlessFolder({
|
||||
serverlessFunction: serverlessFunctionToDuplicate,
|
||||
version,
|
||||
}),
|
||||
},
|
||||
to: {
|
||||
folderPath: getServerlessFolder({
|
||||
serverlessFunction: newServerlessFunction,
|
||||
version: 'draft',
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
return newServerlessFunction;
|
||||
}
|
||||
|
||||
private async throttleExecution(workspaceId: string) {
|
||||
try {
|
||||
await this.throttlerService.throttle(
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ export const serverlessFunctionGraphQLApiExceptionHandler = (error: any) => {
|
||||
case ServerlessFunctionExceptionCode.SERVERLESS_FUNCTION_EXECUTION_LIMIT_REACHED:
|
||||
throw new ForbiddenError(error);
|
||||
case ServerlessFunctionExceptionCode.SERVERLESS_FUNCTION_CODE_UNCHANGED:
|
||||
case ServerlessFunctionExceptionCode.SERVERLESS_FUNCTION_CREATE_FAILED:
|
||||
throw error;
|
||||
default: {
|
||||
return assertUnreachable(error.code);
|
||||
|
||||
Reference in New Issue
Block a user