Skip to content

Commit

Permalink
refactor: rename time to millis
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Aug 31, 2022
1 parent 10e7e82 commit c1158b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/lambda/LambdaFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ export default class LambdaFunction {
this.#initialized = true
}

get idleTimeInMinutes() {
return (performance.now() - this.#idleTimeStarted) / 1000 / 60
get idleTimeInMillis() {
return performance.now() - this.#idleTimeStarted
}

get functionName() {
Expand Down
11 changes: 6 additions & 5 deletions src/lambda/LambdaFunctionPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ export default class LambdaFunctionPool {
}

#startCleanTimer() {
const functionCleanupIdleTimeInMillis =
this.#options.functionCleanupIdleTimeSeconds * 1000

// NOTE: don't use setInterval, as it would schedule always a new run,
// regardless of function processing time and e.g. user action (debugging)
this.#timerRef = setTimeout(() => {
// console.log('run cleanup')
this.#pool.forEach((lambdaFunctions) => {
lambdaFunctions.forEach((lambdaFunction) => {
const { idleTimeInMinutes, status } = lambdaFunction
// console.log(idleTimeInMinutes, status)
const { idleTimeInMillis, status } = lambdaFunction

if (
status === 'IDLE' &&
idleTimeInMinutes >=
this.#options.functionCleanupIdleTimeSeconds / 60
idleTimeInMillis >= functionCleanupIdleTimeInMillis * 1000
) {
// console.log(`removed Lambda Function ${lambdaFunction.functionName}`)
lambdaFunction.cleanup()
Expand All @@ -43,7 +44,7 @@ export default class LambdaFunctionPool {

// schedule new timer
this.#startCleanTimer()
}, (this.#options.functionCleanupIdleTimeSeconds * 1000) / 2)
}, functionCleanupIdleTimeInMillis * 1000)
}

#cleanupPool() {
Expand Down

0 comments on commit c1158b2

Please sign in to comment.