Skip to content

Kotless Lifecycle

Vladislav.Tankov edited this page Nov 1, 2019 · 2 revisions

Kotless DSL provides an interface to control and extend lambda lifecycle. It includes extension points for warming and initialization sequences.

Warming

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 cloud provider.

Each call executes the warming sequence. This sequence consists of all existing Kotlin static object-s implementing interface LambdaWarming.

Here is a simple snippet of HTTP connection warming:

object DbKeepAlive: LambdaWarming {
    override fun warmup() {
        Database.sendHeartBeat()
    }
}

Note: by default, warming will only trigger the initialization of Kotless application, if it was not already initialized.

Initialization

On the first call (or during the first warm-up) Kotless will perform the initialization.

During initialization Kotless application scans the code for Kotless resources (like LambdaWarming, ConversionService, and routes) and registers them.

After this ,Kotless will call init on existing Kotlin static object-s implementing interface LambdaInit. The call is guaranteed to only happen once.

You may use LambdaInit to prepare the application before the first execution.