Now that plugins can inter-communicate via the PluginHTTP API call, it would be useful to be able to monitor for changes to the sets of plugin so as to initiate or teardown expectations.
To facilitate this:
introduce a new hook, OnPluginStatusChange() error that is invoked whenever notifyPluginStatusesChanged is called. Note that this hook should not include a payload, but should return an error allowing the plugin to log an exceptional event as needed.
introduce a new API method, GetPluginStatuses(opts *model.PluginStatusOptions) (*model.PluginStatus, error) that gets the plugin statuses of plugins across the cluster, filtered by the given options. It complements the existing GetPluginStatus(id) (*model.PluginStatus, *model.AppError) method.
introduce a helper method to streamline handling a plugin starting/stopping (see below for details)
In an HA environment, the ClusterId can be used to distinguish instances of plugins running on servers in the cluster. A plugin may want to just know about active plugins on his own server. This would be facilitated by the plugin status options parameter:
The struct allows for future extensibility rather than adding a single parameter to the API. Note that another option might be to expose a bit to return the current cluster id, but this feels like we’re exposing internal implementation details that might change in the future.
Plugins are likely to end up writing something like the following:
We should effectively wrap this with a helper so that a plugin can just register a hook like onPluginStart and onPluginStop and probably onPluginInstall.