Skip to main content

Service

Trait Service 

Source
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_replicaset_leader_change(
        &mut self,
        context: &PicoContext,
    ) -> CallbackResult<()> { ... }
    fn on_cluster_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§

Source

type Config: DeserializeOwned

Use this associated type to define configuration of your service.

Provided Methods§

Source

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_replicaset_leader_change, on_config_change or on_cluster_leader_change callbacks in the future return Ok.

§Arguments
  • ctx: instance context
  • new_config: new configuration
  • old_config: previous defined configuration
Source

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 context
  • config: initial configuration
Source

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
Source

fn on_leader_change(&mut self, context: &PicoContext) -> CallbackResult<()>

👎Deprecated since 26.2.1:

this method gets deprecated, in favor of on_replicaset_leader_change for better naming. Both callbacks will be called until the next major release

This method will be deprecated in the next major release in favor of on_replicaset_leader_change. Only the name is changed, so you can easily migrate to the new method.

Source

fn on_replicaset_leader_change( &mut self, context: &PicoContext, ) -> CallbackResult<()>

Called when the replicaset master is changed. This callback will be called on two instances at max - the old replicaset master (if it is accessible) 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_replicaset_leader_change, on_config_change or on_cluster_leader_change callbacks in the future return Ok.

§Arguments
  • context: instance context
Source

fn on_cluster_leader_change( &mut self, context: &PicoContext, ) -> CallbackResult<()>

Called when the raft leader of the cluster is changed This callback will be called on two instances at max - the old cluster leader (if it is accessible) 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_replicaset_leader_change, on_config_change or on_cluster_leader_change callbacks in the future return Ok.

§Arguments
  • context: instance context
Source

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§