Skip to main content

poll_task

Function poll_task 

Source
pub async fn poll_task(
    client: &CloudClient,
    task_id: &str,
    timeout: Duration,
    interval: Duration,
    on_progress: Option<ProgressCallback>,
) -> Result<TaskStateUpdate>
Expand description

Poll a Cloud task until completion

§Arguments

  • client - The Cloud API client
  • task_id - The task ID to poll
  • timeout - Maximum time to wait for completion
  • interval - Time between polling attempts
  • on_progress - Optional callback for progress updates

§Returns

The completed task response, or an error if the task failed or timed out.

§Example

use redisctl_core::{poll_task, ProgressEvent};
use std::time::Duration;

// Create a database (returns TaskStateUpdate)
let task = handler.create(subscription_id, &request).await?;
let task_id = task.task_id.unwrap();

// Poll with progress callback
let completed = poll_task(
    &client,
    &task_id,
    Duration::from_secs(600),
    Duration::from_secs(10),
    Some(Box::new(|event| {
        match event {
            ProgressEvent::Polling { status, elapsed, .. } => {
                println!("Status: {} ({:.0}s)", status, elapsed.as_secs());
            }
            ProgressEvent::Completed { resource_id, .. } => {
                println!("Done! Resource ID: {:?}", resource_id);
            }
            _ => {}
        }
    })),
).await?;