Skip to content

Commit

Permalink
feat: add timeout config prop for functions (#5683)
Browse files Browse the repository at this point in the history
Co-authored-by: Antonio Rodríguez <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 29, 2024
1 parent 3aecbfc commit 7bfd4ea
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/zip-it-and-ship-it/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface FunctionConfig {
zipGo?: boolean
name?: string
generator?: string
timeout?: number

// Temporary configuration property, only meant to be used by the deploy
// configuration API. Once we start emitting ESM files for all ESM functions,
Expand Down
2 changes: 2 additions & 0 deletions packages/zip-it-and-ship-it/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface ListedFunction {
schedule?: string
displayName?: string
generator?: string
timeout?: number
inputModuleFormat?: ModuleFormat
}

Expand Down Expand Up @@ -151,6 +152,7 @@ const getListedFunction = function ({
displayName: config.name,
extension,
generator: config.generator,
timeout: config.timeout,
mainFile,
name,
runtime: runtime.name,
Expand Down
3 changes: 3 additions & 0 deletions packages/zip-it-and-ship-it/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface ManifestFunction {
displayName?: string
bundler?: string
generator?: string
timeout?: number
priority?: number
trafficRules?: TrafficRules
}
Expand Down Expand Up @@ -81,11 +82,13 @@ const formatFunctionForManifest = ({
runtimeVersion,
runtimeAPIVersion,
schedule,
timeout,
}: FunctionResult): ManifestFunction => {
const manifestFunction: ManifestFunction = {
bundler,
displayName,
generator,
timeout,
invocationMode,
buildData: { runtimeAPIVersion },
mainFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type ISCValues = {
trafficRules?: TrafficRules
name?: string
generator?: string
timeout?: number
}

export interface StaticAnalysisResult extends ISCValues {
Expand Down Expand Up @@ -187,6 +188,10 @@ export const parseSource = (source: string, { functionName }: FindISCDeclaration
result.generator = configExport.generator
}

if (typeof configExport.timeout === 'number') {
result.timeout = configExport.timeout
}

if (configExport.method !== undefined) {
result.methods = normalizeMethods(configExport.method, functionName)
}
Expand Down
8 changes: 7 additions & 1 deletion packages/zip-it-and-ship-it/src/runtimes/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ const zipFunction: ZipFunction = async function ({
invocationMode = INVOCATION_MODE.Background
}

const { trafficRules, generator: staticAnalysisGenerator, name: staticAnalysisName } = staticAnalysisResult
const {
trafficRules,
generator: staticAnalysisGenerator,
name: staticAnalysisName,
timeout: staticAnalysisTimeout,
} = staticAnalysisResult

const outputModuleFormat =
extname(finalMainFile) === MODULE_FILE_EXTENSION.MJS ? MODULE_FORMAT.ESM : MODULE_FORMAT.COMMONJS
Expand All @@ -154,6 +159,7 @@ const zipFunction: ZipFunction = async function ({
displayName: staticAnalysisName || config?.name,
entryFilename: zipPath.entryFilename,
generator: staticAnalysisGenerator || config?.generator || getInternalValue(isInternal),
timeout: staticAnalysisTimeout || config?.timeout,
inputs,
includedFiles,
staticAnalysisResult,
Expand Down
1 change: 1 addition & 0 deletions packages/zip-it-and-ship-it/src/runtimes/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface ZipFunctionResult {
config: FunctionConfig
displayName?: string
generator?: string
timeout?: number
inputs?: string[]
includedFiles?: string[]
invocationMode?: InvocationMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ exports[`listFunction > V2 API > listFunction includes metadata properties when
"runtimeAPIVersion": 2,
"schedule": undefined,
"srcFile": undefined,
"timeout": undefined,
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`listFunctions > V2 API > listFunctions includes runtimeAPIVersion when
"runtimeAPIVersion": 2,
"schedule": undefined,
"srcFile": undefined,
"timeout": undefined,
}
`;

Expand All @@ -28,6 +29,7 @@ exports[`listFunctions > v1 > Can list function main files from multiple source
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -40,6 +42,7 @@ exports[`listFunctions > v1 > Can list function main files from multiple source
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -52,6 +55,7 @@ exports[`listFunctions > v1 > Can list function main files from multiple source
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -64,6 +68,7 @@ exports[`listFunctions > v1 > Can list function main files from multiple source
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcFile": undefined,
"timeout": undefined,
},
]
`;
Expand All @@ -81,6 +86,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -93,6 +99,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -105,6 +112,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -117,6 +125,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -129,6 +138,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -141,6 +151,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -153,6 +164,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions()
"runtimeAPIVersion": undefined,
"schedule": undefined,
"srcFile": undefined,
"timeout": undefined,
},
]
`;
Expand All @@ -170,6 +182,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -182,6 +195,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -194,6 +208,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -206,6 +221,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -218,6 +234,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -230,6 +247,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -242,6 +260,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -254,6 +273,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -266,6 +286,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -278,6 +299,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -290,6 +312,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -302,6 +325,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcFile": undefined,
"timeout": undefined,
},
{
"displayName": undefined,
Expand All @@ -314,6 +338,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio
"runtimeAPIVersion": 1,
"schedule": "@daily",
"srcFile": undefined,
"timeout": undefined,
},
]
`;
Loading

0 comments on commit 7bfd4ea

Please sign in to comment.