Core
Framework v2.x
2

Install #

Available since 2.12.0

Register code executed when the application starts, and only once on any given environment. Once successfully executed, the code associated to an install identifier will never be run again on that environment.

This method can only be used before the application is started. If the handler throws, the application won't start.

install (id: string, handler: () => Promise<void>, description?: string): void

ArgumentTypeDescription
id
string
Unique identifier of this installation
handler
() => Promise<void>
Function to execute only once
description
string
Optional description of the installation

Behavior #

When the application starts, Kuzzle runs the registered installations in order:

  • each installation id is recorded in the private installations collection of the kuzzle index once its handler succeeded; an installation whose id is already recorded is skipped,
  • installations run under a cluster-wide lock: only one node runs them at a time, and the other nodes wait (with no time limit) until it is done, then skip what is already recorded,
  • if a handler throws or rejects, the error is wrapped in a plugin.runtime.unexpected_installation_error error and the application does not start.

Errors #

Usage #

app.install('mappings-2.4.3', async () => {
  await app.sdk.collection.updateMapping('nyc-open-data', 'yellow-taxi', {
    properties: { city: { type: 'keyword' } },
  });
}, 'Add the city field to the yellow-taxi mappings');