pub struct LongOperationManager { /* private fields */ }Implementations§
Source§impl LongOperationManager
impl LongOperationManager
pub fn new() -> Self
Sourcepub fn set_event_hub(&mut self, event_hub: &Arc<EventHub>)
pub fn set_event_hub(&mut self, event_hub: &Arc<EventHub>)
Inject the event hub to allow sending long operation related events
Sourcepub fn start_operation<Op: LongOperation>(&self, operation: Op) -> String
pub fn start_operation<Op: LongOperation>(&self, operation: Op) -> String
Start a new long operation and return its ID
Sourcepub fn get_operation_status(&self, id: &str) -> Option<OperationStatus>
pub fn get_operation_status(&self, id: &str) -> Option<OperationStatus>
Get the status of an operation
Sourcepub fn get_operation_progress(&self, id: &str) -> Option<OperationProgress>
pub fn get_operation_progress(&self, id: &str) -> Option<OperationProgress>
Get the progress of an operation
Sourcepub fn cancel_operation(&self, id: &str) -> bool
pub fn cancel_operation(&self, id: &str) -> bool
Cancel an operation
Sourcepub fn is_operation_finished(&self, id: &str) -> Option<bool>
pub fn is_operation_finished(&self, id: &str) -> Option<bool>
Check if an operation is finished
Sourcepub fn cleanup_finished_operations(&self)
pub fn cleanup_finished_operations(&self)
Remove finished operations from memory
Sourcepub fn list_operations(&self) -> Vec<String>
pub fn list_operations(&self) -> Vec<String>
Get list of all operation IDs
Sourcepub fn get_operations_summary(
&self,
) -> Vec<(String, OperationStatus, OperationProgress)>
pub fn get_operations_summary( &self, ) -> Vec<(String, OperationStatus, OperationProgress)>
Get summary of all operations
Sourcepub fn store_operation_result<T: Serialize>(
&self,
id: &str,
result: T,
) -> Result<()>
pub fn store_operation_result<T: Serialize>( &self, id: &str, result: T, ) -> Result<()>
Store an operation result
Sourcepub fn get_operation_result(&self, id: &str) -> Option<String>
pub fn get_operation_result(&self, id: &str) -> Option<String>
Get an operation result
Sourcepub fn completion_signal(&self) -> Arc<OperationCompletion> ⓘ
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);Sourcepub fn wait_for_operation(&self, id: &str, timeout: Option<Duration>) -> bool
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.