Skip to content

V1 params #1255

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

Merged
merged 3 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
34 changes: 22 additions & 12 deletions src/v1/cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { DeploymentOptions } from "./function-configuration";
export { Request, Response };
import { convertIfPresent, copyIfPresent } from "../common/encoding";
import { ManifestEndpoint, ManifestRequiredAPI } from "../runtime/manifest";
import { Expression } from "../params";

export { Change } from "../common/change";

Expand Down Expand Up @@ -475,17 +476,26 @@ export function optionsToEndpoint(options: DeploymentOptions): ManifestEndpoint
endpoint.vpc = { connector: options.vpcConnector };
convertIfPresent(endpoint.vpc, options, "egressSettings", "vpcConnectorEgressSettings");
}
convertIfPresent(endpoint, options, "availableMemoryMb", "memory", (mem) => {
const memoryLookup = {
"128MB": 128,
"256MB": 256,
"512MB": 512,
"1GB": 1024,
"2GB": 2048,
"4GB": 4096,
"8GB": 8192,
};
return memoryLookup[mem];
});
convertIfPresent(
endpoint,
options,
"availableMemoryMb",
"memory",
(mem: string | Expression<number>) => {
if (typeof mem === "string") {
const memoryLookup = {
"128MB": 128,
"256MB": 256,
"512MB": 512,
"1GB": 1024,
"2GB": 2048,
"4GB": 4096,
"8GB": 8192,
};
return memoryLookup[mem];
}
return mem;
}
);
return endpoint;
}
6 changes: 5 additions & 1 deletion src/v1/function-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ import * as testLab from "./providers/testLab";
* @throws { Error } Memory and TimeoutSeconds values must be valid.
*/
function assertRuntimeOptionsValid(runtimeOptions: RuntimeOptions): boolean {
if (runtimeOptions.memory && !VALID_MEMORY_OPTIONS.includes(runtimeOptions.memory)) {
if (
runtimeOptions.memory &&
typeof runtimeOptions.memory === "string" &&
!VALID_MEMORY_OPTIONS.includes(runtimeOptions.memory)
) {
throw new Error(
`The only valid memory allocation values are: ${VALID_MEMORY_OPTIONS.join(", ")}`
);
Expand Down
8 changes: 4 additions & 4 deletions src/v1/function-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,23 @@ export interface RuntimeOptions {
/**
* Amount of memory to allocate to the function.
*/
memory?: typeof VALID_MEMORY_OPTIONS[number];
memory?: typeof VALID_MEMORY_OPTIONS[number] | Expression<number>;
/**
* Timeout for the function in seconds, possible values are 0 to 540.
*/
timeoutSeconds?: number;
timeoutSeconds?: number | Expression<number>;

/**
* Min number of actual instances to be running at a given time.
* Instances will be billed for memory allocation and 10% of CPU allocation
* while idle.
*/
minInstances?: number;
minInstances?: number | Expression<number>;

/**
* Max number of actual instances allowed to be running in parallel.
*/
maxInstances?: number;
maxInstances?: number | Expression<number>;

/**
* Connect cloud function to specified VPC connector.
Expand Down