serverless-offline 11.1.0 → 11.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lambda/LambdaFunctionPool.js +19 -11
package/package.json
CHANGED
|
@@ -25,9 +25,11 @@ export default class LambdaFunctionPool {
|
|
|
25
25
|
|
|
26
26
|
// NOTE: don't use setInterval, as it would schedule always a new run,
|
|
27
27
|
// regardless of function processing time and e.g. user action (debugging)
|
|
28
|
-
this.#timerRef = setTimeout(() => {
|
|
28
|
+
this.#timerRef = setTimeout(async () => {
|
|
29
|
+
const cleanupWait = []
|
|
30
|
+
|
|
29
31
|
// console.log('run cleanup')
|
|
30
|
-
this.#pool.forEach((lambdaFunctions) => {
|
|
32
|
+
this.#pool.forEach((lambdaFunctions, functionKey) => {
|
|
31
33
|
lambdaFunctions.forEach((lambdaFunction) => {
|
|
32
34
|
const { idleTimeInMillis, status } = lambdaFunction
|
|
33
35
|
|
|
@@ -35,37 +37,43 @@ export default class LambdaFunctionPool {
|
|
|
35
37
|
status === 'IDLE' &&
|
|
36
38
|
idleTimeInMillis >= functionCleanupIdleTimeInMillis
|
|
37
39
|
) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
cleanupWait.push(lambdaFunction.cleanup())
|
|
41
|
+
|
|
40
42
|
lambdaFunctions.delete(lambdaFunction)
|
|
41
43
|
}
|
|
42
44
|
})
|
|
45
|
+
|
|
46
|
+
if (lambdaFunctions.size === 0) {
|
|
47
|
+
this.#pool.delete(functionKey)
|
|
48
|
+
}
|
|
43
49
|
})
|
|
44
50
|
|
|
51
|
+
await Promise.all(cleanupWait)
|
|
52
|
+
|
|
45
53
|
// schedule new timer
|
|
46
54
|
this.#startCleanTimer()
|
|
47
55
|
}, functionCleanupIdleTimeInMillis)
|
|
48
56
|
}
|
|
49
57
|
|
|
50
|
-
#cleanupPool() {
|
|
51
|
-
const
|
|
58
|
+
async #cleanupPool() {
|
|
59
|
+
const cleanupWait = []
|
|
52
60
|
|
|
53
61
|
this.#pool.forEach((lambdaFunctions) => {
|
|
54
62
|
lambdaFunctions.forEach((lambdaFunction) => {
|
|
55
|
-
|
|
56
|
-
wait.push(lambdaFunction.cleanup())
|
|
57
|
-
lambdaFunctions.delete(lambdaFunction)
|
|
63
|
+
cleanupWait.push(lambdaFunction.cleanup())
|
|
58
64
|
})
|
|
59
65
|
})
|
|
60
66
|
|
|
61
|
-
|
|
67
|
+
await Promise.all(cleanupWait)
|
|
68
|
+
|
|
69
|
+
this.#pool.clear()
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
// TODO make sure to call this
|
|
65
73
|
async cleanup() {
|
|
66
74
|
clearTimeout(this.#timerRef)
|
|
67
75
|
|
|
68
|
-
|
|
76
|
+
await this.#cleanupPool()
|
|
69
77
|
}
|
|
70
78
|
|
|
71
79
|
get(functionKey, functionDefinition) {
|