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| Argument | Type | Description |
|---|---|---|
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
idis recorded in the privateinstallationscollection of thekuzzleindex once its handler succeeded; an installation whoseidis 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 #
- plugin.runtime.already_started: the application is already started
- validation.assert.invalid_type:
idis not a string, orhandleris not a function
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');