Skip to content

Commit

Permalink
Add command line option for function cleanup idle time.
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-marsh committed Apr 29, 2020
1 parent 49e5121 commit 2551156
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/config/commandOptions.js
Expand Up @@ -72,4 +72,7 @@ export default {
useDocker: {
usage: 'Uses docker for node/python/ruby',
},
functionCleanupIdleTimeSeconds: {
usage: 'Number of seconds until an idle function is eligible for cleanup',
},
}
1 change: 1 addition & 0 deletions src/config/defaultOptions.js
Expand Up @@ -22,4 +22,5 @@ export default {
useWorkerThreads: false,
websocketPort: 3001,
useDocker: false,
functionCleanupIdleTimeSeconds: 60,
}
9 changes: 6 additions & 3 deletions src/lambda/LambdaFunctionPool.js
Expand Up @@ -24,8 +24,11 @@ export default class LambdaFunctionPool {
const { idleTimeInMinutes, status } = lambdaFunction
// console.log(idleTimeInMinutes, status)

// 45 // TODO config, or maybe option?
if (status === 'IDLE' && idleTimeInMinutes >= 1) {
if (
status === 'IDLE' &&
idleTimeInMinutes >=
this.#options.functionCleanupIdleTimeSeconds / 60
) {
// console.log(`removed Lambda Function ${lambdaFunction.functionName}`)
lambdaFunction.cleanup()
lambdaFunctions.delete(lambdaFunction)
Expand All @@ -35,7 +38,7 @@ export default class LambdaFunctionPool {

// schedule new timer
this._startCleanTimer()
}, 10000) // TODO: config, or maybe option?
}, (this.#options.functionCleanupIdleTimeSeconds * 1000) / 2)
}

_cleanupPool() {
Expand Down

0 comments on commit 2551156

Please sign in to comment.