pub trait Service {
type Config: DeserializeOwned;
// Provided methods
fn on_config_change(
&mut self,
ctx: &PicoContext,
new_config: Self::Config,
old_config: Self::Config,
) -> CallbackResult<()> { ... }
fn on_start(
&mut self,
context: &PicoContext,
config: Self::Config,
) -> CallbackResult<()> { ... }
fn on_stop(&mut self, context: &PicoContext) -> CallbackResult<()> { ... }
fn on_leader_change(&mut self, context: &PicoContext) -> CallbackResult<()> { ... }
fn on_health_check(&self, context: &PicoContext) -> CallbackResult<()> { ... }
}
Expand description
Service trait. Implement it in your code to create a service.
Required Associated Types§
Sourcetype Config: DeserializeOwned
type Config: DeserializeOwned
Use this associated type to define configuration of your service.
Provided Methods§
Sourcefn on_config_change(
&mut self,
ctx: &PicoContext,
new_config: Self::Config,
old_config: Self::Config,
) -> CallbackResult<()>
fn on_config_change( &mut self, ctx: &PicoContext, new_config: Self::Config, old_config: Self::Config, ) -> CallbackResult<()>
Callback to handle service configuration change once instance receives it.
§Idempotency
WARNING This callback may be called several times in a row. It is the responsibility of the plugin author to make this function idempotent.
§Poison
Return an error here to poison current instance. This will not cancel reconfiguration process, but will mark instance as unavailable for rpc messaging.
Instance can be “healed”
if any of on_leader_change
or on_config_change
callbacks in the future return Ok
.
§Arguments
ctx
: instance contextnew_config
: new configurationold_config
: previous defined configuration
Sourcefn on_start(
&mut self,
context: &PicoContext,
config: Self::Config,
) -> CallbackResult<()>
fn on_start( &mut self, context: &PicoContext, config: Self::Config, ) -> CallbackResult<()>
Called at service start on every instance.
§Idempotency
WARNING This callback may be called several times in a row (without
any calls to Self::on_stop
). It is the responsibility of the plugin
author to make this function idempotent.
An error returned here abort plugin load clusterwide thus forcing
on_stop
callback execution on every instance.
§Arguments
context
: instance contextconfig
: initial configuration
Sourcefn on_stop(&mut self, context: &PicoContext) -> CallbackResult<()>
fn on_stop(&mut self, context: &PicoContext) -> CallbackResult<()>
Called on instance shutdown, plugin removal or failure of the initial load. Returned error will only be logged causing no effects on plugin lifecycle.
§Idempotency
WARNING This callback may be called several times in a row. It is the responsibility of the plugin author to make this function idempotent.
§Arguments
context
: instance context
Sourcefn on_leader_change(&mut self, context: &PicoContext) -> CallbackResult<()>
fn on_leader_change(&mut self, context: &PicoContext) -> CallbackResult<()>
Called when replicaset leader is changed. This callback will be called exactly on two instances - the old leader and the new one.
§Idempotency
WARNING This callback may be called several times in a row. It is the responsibility of the plugin author to make this function idempotent.
§Poison
Return an error here to poison current instance. This will not cancel reconfiguration process, but will mark instance as unavailable for rpc messaging.
Instance can be “healed”
if any of on_leader_change
or on_config_change
callbacks in the future return Ok
.
§Arguments
context
: instance context
Sourcefn on_health_check(&self, context: &PicoContext) -> CallbackResult<()>
fn on_health_check(&self, context: &PicoContext) -> CallbackResult<()>
on_healthcheck
is a callback
that should be called to determine if the service is functioning properly
On an error instance will be poisoned
§Unimplemented
WARNING This feature is not yet implemented. The callback is never called. TODO.