diff --git a/src/lib/functions/netlify-function.ts b/src/lib/functions/netlify-function.ts index baf87fb3a13..b7880d08b03 100644 --- a/src/lib/functions/netlify-function.ts +++ b/src/lib/functions/netlify-function.ts @@ -64,9 +64,23 @@ export default class NetlifyFunction { // main file. public readonly srcPath: string - // Determines whether this is a background function based on the function - // name. - public readonly isBackground: boolean + // Determines whether this is a background function. Checks (in order): + // 1. ZISI build data — `invocationMode === 'background'` captures the + // filename suffix AND the in-source `config.background: true`. + // 2. The TOML config — `[functions.] background = true`. + // 3. The filename suffix as a last-resort fallback (used pre-build and for + // non-ZISI runtimes like Go). + get isBackground(): boolean { + if (this.buildData?.invocationMode === 'background') { + return true + } + + // @ts-expect-error TODO; Update the type and cut a new version of `@netlify/config`. + if (this.config.functions?.[this.name]?.background === true) { + return true + } + return this.name.endsWith(BACKGROUND) + } private buildQueue?: Promise | undefined public buildData?: MappedOmit | undefined @@ -123,8 +137,6 @@ export default class NetlifyFunction { this.settings = settings this.srcPath = srcPath - this.isBackground = name.endsWith(BACKGROUND) - const functionConfig = config.functions?.[name] // @ts-expect-error -- XXX(serhalp): fixed in stack PR (bumps to https://github.com/netlify/build/pull/6165) this.schedule = functionConfig && functionConfig.schedule diff --git a/src/lib/functions/runtimes/index.ts b/src/lib/functions/runtimes/index.ts index cd8c7bdfa0d..eaa9dd4f19f 100644 --- a/src/lib/functions/runtimes/index.ts +++ b/src/lib/functions/runtimes/index.ts @@ -21,6 +21,7 @@ export type BaseBuildResult = { // TODO(serhalp): This module and type shouldn't know about these zisi types. Refactor to allow the JS runtime's zisi // builder to define this on its extended base build result type. excludedRoutes?: Route[] | undefined + invocationMode?: string | undefined routes?: ExtendedRoute[] | undefined runtimeAPIVersion?: number | undefined } diff --git a/src/lib/functions/runtimes/js/builders/zisi.ts b/src/lib/functions/runtimes/js/builders/zisi.ts index 606cd906225..83d471f37db 100644 --- a/src/lib/functions/runtimes/js/builders/zisi.ts +++ b/src/lib/functions/runtimes/js/builders/zisi.ts @@ -23,6 +23,7 @@ const require = createRequire(import.meta.url) export type ZisiBuildResult = BaseBuildResult & { buildPath: string includedFiles: FunctionResult['includedFiles'] + invocationMode: FunctionResult['invocationMode'] outputModuleFormat: FunctionResult['outputModuleFormat'] mainFile: FunctionResult['mainFile'] runtimeAPIVersion: FunctionResult['runtimeAPIVersion'] @@ -66,6 +67,7 @@ const buildFunction = async ({ excludedRoutes, includedFiles, inputs, + invocationMode, mainFile, outputModuleFormat, path: functionPath, @@ -103,6 +105,7 @@ const buildFunction = async ({ buildPath, excludedRoutes, includedFiles, + invocationMode, outputModuleFormat, mainFile, routes, diff --git a/src/utils/deploy/hash-fns.ts b/src/utils/deploy/hash-fns.ts index d025710d9d2..c9edc6379a3 100644 --- a/src/utils/deploy/hash-fns.ts +++ b/src/utils/deploy/hash-fns.ts @@ -187,7 +187,15 @@ const hashFns = async ( const fnConfig = functionZips .filter((func) => Boolean( - func.displayName || func.generator || func.routes || func.buildData || func.priority || func.trafficRules, + func.displayName || + func.generator || + func.routes || + func.buildData || + func.priority || + func.trafficRules || + func.region || + func.memory || + func.vcpu, ), ) .reduce( @@ -197,10 +205,13 @@ const hashFns = async ( display_name: curr.displayName, excluded_routes: curr.excludedRoutes, generator: curr.generator, + memory: curr.memory, + region: curr.region, routes: curr.routes, build_data: curr.buildData, priority: curr.priority, traffic_rules: trafficRulesConfig(curr.trafficRules), + vcpu: curr.vcpu, }, }), {},