init (abstract) #

Plugins must expose an init function. If it is missing, Kuzzle fails to load the plugin and aborts its start sequence.

The init method is called once during startup, and it is used to initialize the plugin.

Arguments #

init(config: JSONObject, context: PluginContext);

ArgumentsTypeDescription
config
JSONObject
Contains the custom plugin configuration
context
PluginContext
The plugin context, exposing various accessors, constructors, and helpers. The other sections of this documentation detail the interfaces made available by this object

Return #

The init function can optionally return a promise. If it does, Kuzzle waits for the promise to be resolved before continuing its own initialization.

If a promise is returned, it must be resolved within the configured timeout (see plugins.common.initTimeout in Kuzzle's configuration)

In a cluster, that time includes waiting for cluster-wide locks taken during the init, for instance by storage.bootstrap (every node creates the plugin's collections in turn). If the node holding such a lock stops abruptly, the lock is only released when it expires: the timeout error then names the lock that was awaited.

If a promise is returned and rejected, or if the init function throws an error, Kuzzle aborts its start sequence and shuts down.