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
impl Updater
sourcepub fn new(config: Config) -> Result<Arc<Self>, UpdaterError>
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
sourcepub fn register_action(&self) -> Option<usize>
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.
sourcepub fn deregister_action(&self) -> Option<usize>
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.
sourcepub fn is_safe_to_update(&self) -> bool
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.
sourcepub fn status(&self) -> Status
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.
sourcepub fn set_status(&self, status: Status)
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.
sourcepub fn subscribe(&self) -> Listener<Status>
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.