Struct patchify::client::Updater

source ·
pub struct Updater { /* private fields */ }
Expand description

A service to check for updates at intervals, and upgrade the application.

This struct provides a service that will query the API server at defined intervals, to check for updates. If an update is found, it will be downloaded and installed, and the application will be restarted.

Implementations§

source§

impl Updater

source

pub fn new(config: Config) -> Result<Arc<Self>, UpdaterError>

Creates a new updater service instance.

This function creates a new updater service instance, with the specified configuration. As soon as the service is created, it will start checking for updates.

In order to shut down nicely, Drop is implemented, and will send a message to the internal queue to stop the timer.

§Parameters
  • config - The configuration for the updater service.
§Errors
source

pub fn register_action(&self) -> Option<usize>

Registers a critical action.

This function increments the critical actions counter, preventing the application from being updated while the critical action is in progress.

It returns the likely new value of the counter, or None if the counter overflows or if starting a new action is not permitted due to a pending update. The new value is likely rather than guaranteed due to the effect of concurrent updates, and therefore is the value known and set at the time it was incremented, and may not be the value by the time the function returns.

source

pub fn deregister_action(&self) -> Option<usize>

Deregisters a critical action.

This function decrements the critical actions counter, allowing the application to be updated once the count reaches zero.

It returns the likely new value of the counter, or None if the counter underflows. The new value is likely rather than guaranteed due to the effect of concurrent updates, and therefore is the value known and set at the time it was incremented, and may not be the value by the time the function returns.

If a restart is pending, then when the critical actions counter reaches zero, the restart will be triggered.

source

pub fn is_safe_to_update(&self) -> bool

Checks if it is safe to update.

This function checks the critical actions counter, to see if it is safe to update the application — i.e. if the counter is zero.

Note that at present this is a naive implementation that does not lock the counter, and so it is possible that the counter could change between the time of checking and the time of updating.

source

pub fn status(&self) -> Status

Gets the current status of the updater.

This function returns the current status of the updater, correct at the time of calling.

Note that the status may change between the time of calling and the time of processing the result.

source

pub fn set_status(&self, status: Status)

Sets the current status of the updater.

This function changes the current status of the updater to the specified value.

source

pub fn subscribe(&self) -> Listener<Status>

Subscribes to the status change event broadcaster.

This function provides a receiver that is subscribed to the status change event broadcaster, so that every time the status changes, it will be notified.

At present this simply subscribes to all status change events, but it may be enhanced in future to allow for filtering.

Trait Implementations§

source§

impl Debug for Updater

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Updater

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more