Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add longRunning/Persistent function flag #1703

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/cloudAdapter/cloudAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type GenezioCloudInput =
maxConcurrentRequestsPerInstance?: number;
maxConcurrentInstances?: number;
cooldownTime?: number;
persistent?: boolean;
}
| {
type: GenezioCloudInputType.FUNCTION;
Expand All @@ -64,6 +65,7 @@ export type GenezioCloudInput =
maxConcurrentRequestsPerInstance?: number;
maxConcurrentInstances?: number;
cooldownTime?: number;
persistent?: boolean;
};

export type GenezioCloudResultClass = {
Expand Down
1 change: 1 addition & 0 deletions src/commands/deploy/docker/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export async function dockerDeploy(options: GenezioDeployOptions) {
config.container!.maxConcurrentRequestsPerInstance,
maxConcurrentInstances: config.container!.maxConcurrentInstances,
cooldownTime: config.container!.cooldownTime,
persistent: config.container!.persistent,
},
],
projectConfiguration,
Expand Down
2 changes: 2 additions & 0 deletions src/commands/deploy/genezio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ export async function deployClasses(
maxConcurrentRequestsPerInstance: element.maxConcurrentRequestsPerInstance,
maxConcurrentInstances: element.maxConcurrentInstances,
cooldownTime: element.cooldownTime,
persistent: element.persistent,
};
},
);
Expand Down Expand Up @@ -742,6 +743,7 @@ export async function functionToCloudInput(
maxConcurrentRequestsPerInstance: functionElement.maxConcurrentRequestsPerInstance,
maxConcurrentInstances: functionElement.maxConcurrentInstances,
cooldownTime: functionElement.cooldownTime,
persistent: functionElement.persistent,
metadata: metadata,
};
}
Expand Down
1 change: 1 addition & 0 deletions src/commands/deploy/zip/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export async function zipDeploy(options: GenezioDeployOptions) {
maxConcurrentRequestsPerInstance: f.maxConcurrentRequestsPerInstance,
maxConcurrentInstances: f.maxConcurrentInstances,
cooldownTime: f.cooldownTime,
persistent: f.persistent,
};
});

Expand Down
1 change: 1 addition & 0 deletions src/generateSdk/generateSdkApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export function mapYamlClassToSdkClassConfiguration(
maxConcurrentRequestsPerInstance: yamlClass.maxConcurrentRequestsPerInstance,
maxConcurrentInstances: yamlClass.maxConcurrentInstances,
cooldownTime: yamlClass.cooldownTime,
persistent: yamlClass.persistent,
};
});
}
Expand Down
1 change: 1 addition & 0 deletions src/generateSdk/utils/getAstSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function getAstSummary(classesInfo: SdkGeneratorClassesInfoInput[]): AstS
maxConcurrentInstances:
classConfiguration.classConfiguration.maxConcurrentInstances,
cooldownTime: classConfiguration.classConfiguration.cooldownTime,
persistent: classConfiguration.classConfiguration.persistent,
};
return classInfo;
});
Expand Down
1 change: 1 addition & 0 deletions src/models/astSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type AstSummaryClass = {
maxConcurrentRequestsPerInstance?: number;
maxConcurrentInstances?: number;
cooldownTime?: number;
persistent?: boolean;
};

export type AstSummary = {
Expand Down
1 change: 1 addition & 0 deletions src/models/genezioModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,5 @@ export type SdkClassConfiguration = {
maxConcurrentRequestsPerInstance?: number;
maxConcurrentInstances?: number;
cooldownTime?: number;
persistent?: boolean;
};
8 changes: 8 additions & 0 deletions src/models/projectConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class ClassConfiguration {
maxConcurrentRequestsPerInstance?: number;
maxConcurrentInstances?: number;
cooldownTime?: number;
persistent?: boolean;

constructor(
name: string,
Expand All @@ -91,6 +92,7 @@ export class ClassConfiguration {
maxConcurrentRequestsPerInstance?: number,
maxConcurrentInstances?: number,
cooldownTime?: number,
persistent?: boolean,
) {
this.name = name;
this.path = path;
Expand All @@ -106,6 +108,7 @@ export class ClassConfiguration {
this.maxConcurrentRequestsPerInstance = maxConcurrentRequestsPerInstance;
this.maxConcurrentInstances = maxConcurrentInstances;
this.cooldownTime = cooldownTime;
this.persistent = persistent;
}
}

Expand All @@ -122,6 +125,7 @@ export class FunctionConfiguration {
maxConcurrentRequestsPerInstance?: number;
maxConcurrentInstances?: number;
cooldownTime?: number;
persistent?: boolean;

constructor(
name: string,
Expand All @@ -136,6 +140,7 @@ export class FunctionConfiguration {
maxConcurrentRequestsPerInstance?: number,
maxConcurrentInstances?: number,
cooldownTime?: number,
persistent?: boolean,
) {
this.name = name;
this.path = path;
Expand All @@ -149,6 +154,7 @@ export class FunctionConfiguration {
this.maxConcurrentRequestsPerInstance = maxConcurrentRequestsPerInstance;
this.maxConcurrentInstances = maxConcurrentInstances;
this.cooldownTime = cooldownTime;
this.persistent = persistent;
}
}

Expand Down Expand Up @@ -300,6 +306,7 @@ export class ProjectConfiguration {
maxConcurrentRequestsPerInstance: c.maxConcurrentRequestsPerInstance,
maxConcurrentInstances: c.maxConcurrentInstances,
cooldownTime: c.cooldownTime,
persistent: c.persistent,
};
});

Expand All @@ -318,6 +325,7 @@ export class ProjectConfiguration {
maxConcurrentRequestsPerInstance: f.maxConcurrentRequestsPerInstance,
maxConcurrentInstances: f.maxConcurrentInstances,
cooldownTime: f.cooldownTime,
persistent: f.persistent,
};
}) || [];
}
Expand Down
3 changes: 3 additions & 0 deletions src/projectConfiguration/yaml/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function parseGenezioConfig(config: unknown) {
return true;
}, "The maximum number of concurrent instances should be greater than 0."),
cooldownTime: zod.number().optional(),
persistent: zod.boolean().optional(),
});

const functionsSchema = zod
Expand Down Expand Up @@ -162,6 +163,7 @@ function parseGenezioConfig(config: unknown) {
return true;
}, "The maximum number of concurrent instances should be greater than 0."),
cooldownTime: zod.number().optional(),
persistent: zod.boolean().optional(),
})
.refine(
({ type, handler }) => !(type === FunctionType.aws && !handler),
Expand Down Expand Up @@ -358,6 +360,7 @@ function parseGenezioConfig(config: unknown) {
return true;
}, "The maximum number of concurrent instances should be greater than 0."),
cooldownTime: zod.number().optional(),
persistent: zod.boolean().optional(),
environment: environmentSchema.optional(),
});

Expand Down
1 change: 1 addition & 0 deletions src/requests/deployCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export async function deployRequest(
maxConcurrentRequestsPerInstance: input?.maxConcurrentRequestsPerInstance,
maxConcurrentInstances: input?.maxConcurrentInstances,
cooldownTime: input?.cooldownTime,
persistent: input?.persistent,
};
}) ?? [],
projectName: projectConfiguration.name,
Expand Down
5 changes: 5 additions & 0 deletions src/utils/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export async function scanClassesForDecorators(
let maxConcurrentRequestsPerInstance: number | undefined;
let maxConcurrentInstances: number | undefined;
let cooldownTime: number | undefined;
let persistent: boolean | undefined;
const methods = classInfo[0].methods
.map((m) => {
const genezioMethodDecorator = m.decorators.find(
Expand Down Expand Up @@ -119,6 +120,9 @@ export async function scanClassesForDecorators(
cooldownTime = deployDecoratorFound.arguments["cooldownTime"] as
| number
| undefined;
persistent = deployDecoratorFound.arguments["persistent"] as
| boolean
| undefined;
}

classes.push({
Expand All @@ -131,6 +135,7 @@ export async function scanClassesForDecorators(
maxConcurrentRequestsPerInstance: maxConcurrentRequestsPerInstance,
maxConcurrentInstances: maxConcurrentInstances,
cooldownTime: cooldownTime,
persistent: persistent,
methods: methods,
});
} else if (r && deployDecoratorFound) {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/decorators/baseDecoratorExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export abstract class DecoratorExtractor {
key === "storageSize" ||
key === "maxConcurrentRequestsPerInstance" ||
key === "maxConcurrentInstances" ||
key === "cooldownTime"
key === "cooldownTime" ||
key === "persistent"
) {
transformedValue = parseInt(value);
if (isNaN(transformedValue)) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/decorators/decoratorTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type MethodInfo = {

export type ClassDecoratorInfo = {
name: string;
arguments?: { [key: string]: string | number };
arguments?: { [key: string]: string | number | boolean };
};

export type ClassInfo = {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export async function resolveConfigurationVariable(
isLocal?: boolean;
port?: number;
},
): Promise<string | number> {
): Promise<string | number | boolean> {
if (options?.isLocal && !options?.port) {
options.port = PORT_LOCAL_ENVIRONMENT;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const displayHint = function (message: string) {
* @param {string} value - The value to replace the placeholder with.
* @returns {string} - The updated string with the placeholder replaced.
*/
export function replaceExpression(expression: string, value: string|number): string {
export function replaceExpression(expression: string, value: string|number|boolean): string {
// ${{<variable>}} can be any alphanumeric string with special characters
const placeholderPattern = /\${{[A-Za-z0-9\s/.\-_]+}}/;
return expression.replace(placeholderPattern, value.toString());
Expand Down