Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC for externally triggering cleanup of lambda functions #1093

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/ServerlessOffline.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export default class ServerlessOffline {
usage:
'Simulates API Gateway to call your lambda functions offline using backward compatible initialization.',
},
functionsUpdated: {
type: 'entrypoint',
lifecycleEvents: ['cleanup'],
},
},
lifecycleEvents: ['start'],
options: commandOptions,
Expand All @@ -45,6 +49,7 @@ export default class ServerlessOffline {
this.hooks = {
'offline:start:init': this.start.bind(this),
'offline:start:ready': this.ready.bind(this),
'offline:functionsUpdated:cleanup': this.cleanupFunctions.bind(this),
'offline:start': this._startWithExplicitEnd.bind(this),
'offline:start:end': this.end.bind(this),
}
Expand Down Expand Up @@ -136,6 +141,13 @@ export default class ServerlessOffline {
}
}

async cleanupFunctions() {
if (this.#lambda) {
serverlessLog('Forcing cleanup of Lambda functions')
await this.#lambda.cleanup()
}
}

/**
* Entry point for the plugin (sls offline) when running 'sls offline'
* The call to this.end() would terminate the process before 'offline:start:end' could be consumed
Expand Down