8725 workflow avoid serverless function autosave errors (#8916)

See issue #8725 
- Build function asynchronously using a job
- prevent useless builds
- run promises simultaneously

Todo:
- fix outputSchema computing
This commit is contained in:
martmull
2024-12-06 11:13:12 +01:00
committed by GitHub
parent a8867fd090
commit 2b3b073570
9 changed files with 129 additions and 51 deletions

View File

@ -54,6 +54,8 @@ import { compileTypescript } from 'src/engine/core-modules/serverless/drivers/ut
import { ENV_FILE_NAME } from 'src/engine/core-modules/serverless/drivers/constants/env-file-name';
import { OUTDIR_FOLDER } from 'src/engine/core-modules/serverless/drivers/constants/outdir-folder';
const UPDATE_FUNCTION_DURATION_TIMEOUT_IN_SECONDS = 30;
export interface LambdaDriverOptions extends LambdaClientConfig {
fileStorageService: FileStorageService;
region: string;
@ -75,7 +77,7 @@ export class LambdaDriver implements ServerlessDriver {
private async waitFunctionUpdates(
serverlessFunctionId: string,
maxWaitTime: number,
maxWaitTime: number = UPDATE_FUNCTION_DURATION_TIMEOUT_IN_SECONDS,
) {
const waitParams = { FunctionName: serverlessFunctionId };
@ -263,12 +265,12 @@ export class LambdaDriver implements ServerlessDriver {
updateConfigurationParams,
);
await this.waitFunctionUpdates(serverlessFunction.id, 10);
await this.waitFunctionUpdates(serverlessFunction.id);
await this.lambdaClient.send(updateConfigurationCommand);
}
await this.waitFunctionUpdates(serverlessFunction.id, 10);
await this.waitFunctionUpdates(serverlessFunction.id);
}
async publish(serverlessFunction: ServerlessFunctionEntity) {
@ -316,7 +318,9 @@ export class LambdaDriver implements ServerlessDriver {
? functionToExecute.id
: `${functionToExecute.id}:${computedVersion}`;
await this.waitFunctionUpdates(functionToExecute.id, 10);
if (version === 'draft') {
await this.waitFunctionUpdates(functionToExecute.id);
}
const startTime = Date.now();

View File

@ -12,14 +12,10 @@ export const getLayerDependencies = async (
layerVersion: number | 'latest',
): Promise<LayerDependencies> => {
const lastVersionLayerDirName = getLayerDependenciesDirName(layerVersion);
const packageJson = await fs.readFile(
join(lastVersionLayerDirName, 'package.json'),
'utf8',
);
const yarnLock = await fs.readFile(
join(lastVersionLayerDirName, 'yarn.lock'),
'utf8',
);
const [packageJson, yarnLock] = await Promise.all([
fs.readFile(join(lastVersionLayerDirName, 'package.json'), 'utf8'),
fs.readFile(join(lastVersionLayerDirName, 'yarn.lock'), 'utf8'),
]);
return { packageJson: JSON.parse(packageJson), yarnLock };
};