Skip to content

Commit

Permalink
feat: add support for deploying scheduled functions (#3885)
Browse files Browse the repository at this point in the history
* feat: add support for deploying scheduled functions

* refactor: remove unnecessary feature flag usage

* refactor: replace reduce with map + filter

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
eduardoboucas and kodiakhq[bot] committed Dec 21, 2021
1 parent 829dcd6 commit 48961f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
31 changes: 16 additions & 15 deletions src/utils/deploy/deploy-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ const deploySite = async (
phase: 'start',
})

const [{ files, filesShaMap }, { fnShaMap, functions, functionsWithNativeModules }] = await Promise.all([
hashFiles(dir, configPath, { concurrentHash, hashAlgorithm, assetType, statusCb, filter }),
hashFns(fnDir, {
functionsConfig,
tmpDir,
concurrentHash,
hashAlgorithm,
statusCb,
assetType,
rootDir,
manifestPath,
skipFunctionsCache,
}),
])

const [{ files, filesShaMap }, { fnShaMap, functionSchedules, functions, functionsWithNativeModules }] =
await Promise.all([
hashFiles(dir, configPath, { concurrentHash, hashAlgorithm, assetType, statusCb, filter }),
hashFns(fnDir, {
functionsConfig,
tmpDir,
concurrentHash,
hashAlgorithm,
statusCb,
assetType,
rootDir,
manifestPath,
skipFunctionsCache,
}),
])
const filesCount = Object.keys(files).length
const functionsCount = Object.keys(functions).length
const hasFunctionDirectories = fnDir.length !== 0
Expand Down Expand Up @@ -106,6 +106,7 @@ For more information, visit https://ntl.fyi/cli-native-modules.`)
body: {
files,
functions,
function_schedules: functionSchedules,
async: Object.keys(files).length > syncFileLimit,
branch,
draft,
Expand Down
6 changes: 4 additions & 2 deletions src/utils/deploy/hash-fns.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ const hashFns = async (
normalizedPath: path.basename(functionPath, path.extname(functionPath)),
runtime,
}))

const functionSchedules = functionZips
.map(({ name, schedule }) => schedule && { name, cron: schedule })
.filter(Boolean)
const functionsWithNativeModules = functionZips.filter(
({ nativeNodeModules }) => nativeNodeModules !== undefined && Object.keys(nativeNodeModules).length !== 0,
)
Expand All @@ -125,7 +127,7 @@ const hashFns = async (

await pump(functionStream, hasher, manifestCollector)

return { functions, functionsWithNativeModules, fnShaMap }
return { functionSchedules, functions, functionsWithNativeModules, fnShaMap }
}

module.exports = { hashFns }

1 comment on commit 48961f6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 355 MB

Please sign in to comment.