Skip to main content

LongOperationManager

Struct LongOperationManager 

Source
pub struct LongOperationManager { /* private fields */ }

Implementations§

Source§

impl LongOperationManager

Source

pub fn new() -> Self

Source

pub fn set_event_hub(&mut self, event_hub: &Arc<EventHub>)

Inject the event hub to allow sending long operation related events

Source

pub fn start_operation<Op: LongOperation>(&self, operation: Op) -> String

Start a new long operation and return its ID

Source

pub fn get_operation_status(&self, id: &str) -> Option<OperationStatus>

Get the status of an operation

Source

pub fn get_operation_progress(&self, id: &str) -> Option<OperationProgress>

Get the progress of an operation

Source

pub fn cancel_operation(&self, id: &str) -> bool

Cancel an operation

Source

pub fn is_operation_finished(&self, id: &str) -> Option<bool>

Check if an operation is finished

Source

pub fn cleanup_finished_operations(&self)

Remove finished operations from memory

Source

pub fn list_operations(&self) -> Vec<String>

Get list of all operation IDs

Source

pub fn get_operations_summary( &self, ) -> Vec<(String, OperationStatus, OperationProgress)>

Get summary of all operations

Source

pub fn store_operation_result<T: Serialize>( &self, id: &str, result: T, ) -> Result<()>

Store an operation result

Source

pub fn get_operation_result(&self, id: &str) -> Option<String>

Get an operation result

Source

pub fn completion_signal(&self) -> Arc<OperationCompletion>

A cloneable handle to the completion signal — the supported way to block until an operation finishes instead of re-checking it on a timer.

Handed out as an Arc by design. A manager is normally reached through a shared lock, and blocking while holding that lock would stall every other operation query for as long as the wait lasts. So take the handle, drop the manager lock, then wait:

let completion = ctx.long_operation_manager.lock().completion_signal();
// manager lock released here
completion.wait_for(&op_id, Some(Duration::from_secs(30)));
let result = ctx.long_operation_manager.lock().get_operation_result(&op_id);
Source

pub fn wait_for_operation(&self, id: &str, timeout: Option<Duration>) -> bool

Block until id finishes; true once it has.

Convenience for an owner holding the manager directly. Do not call this through a shared lock — it blocks for the operation’s whole duration and would hold that lock the entire time; take completion_signal and wait on that instead.

Trait Implementations§

Source§

impl Debug for LongOperationManager

Source§

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

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

impl Default for LongOperationManager

Source§

fn default() -> Self

Returns the “default value” for a 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, 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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.