Repository navigation
Ktor Lifecycle
Vladislav.Tankov edited this page Jun 13, 2020
·
4 revisions
Ktor DSL provides an event to control and extend lambda lifecycle. It includes events for warming and initialization of application.
Kotless' lambdas can be autowarmed. It means that some scheduler will periodically (by default, each 5 minutes) call lambda to make sure it will not be displaced from the hot pool of the cloud provider.
Each call triggers the LambdaWarming event.
Here is a simple snippet of HTTP connection warming subscribed to this event:
app.events {
subscribe(LambdaWarming) {
Database.sendHeartBeat()
}
}On the first call (or during the first warm-up) Ktor will perform the initialization.
After the initialization, an ApplicationStarted event will be triggered.
Here is a simple snippet of Database initialization:
app.events {
subscribe(ApplicationStarted) {
Database.init()
}
}