Enum meilisearch_sdk::tasks::Task
source · pub enum Task {
Enqueued {
content: EnqueuedTask,
},
Processing {
content: EnqueuedTask,
},
Failed {
content: FailedTask,
},
Succeeded {
content: SucceededTask,
},
}Variants§
Enqueued
Fields
§
content: EnqueuedTaskProcessing
Fields
§
content: EnqueuedTaskFailed
Fields
§
content: FailedTaskSucceeded
Fields
§
content: SucceededTaskImplementations§
source§impl Task
impl Task
pub fn get_uid(&self) -> u32
sourcepub async fn wait_for_completion(
self,
client: &Client,
interval: Option<Duration>,
timeout: Option<Duration>
) -> Result<Self, Error>
pub async fn wait_for_completion(
self,
client: &Client,
interval: Option<Duration>,
timeout: Option<Duration>
) -> Result<Self, Error>
Wait until Meilisearch processes a Task, and get its status.
interval = The frequency at which the server should be polled. Default = 50ms
timeout = The maximum time to wait for processing to complete. Default = 5000ms
If the waited time exceeds timeout then an Error::Timeout will be returned.
See also [Client::wait_for_task, Index::wait_for_task].
Example
let client = Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);
let movies = client.index("movies_wait_for_completion");
let status = movies.add_documents(&[
Document { id: 0, kind: "title".into(), value: "The Social Network".to_string() },
Document { id: 1, kind: "title".into(), value: "Harry Potter and the Sorcerer's Stone".to_string() },
], None)
.await
.unwrap()
.wait_for_completion(&client, None, None)
.await
.unwrap();
assert!(matches!(status, Task::Succeeded { .. }));sourcepub fn try_make_index(self, client: &Client) -> Result<Index, Self>
pub fn try_make_index(self, client: &Client) -> Result<Index, Self>
Extract the Index from a successful IndexCreation task.
If the task failed or was not an IndexCreation task it return itself.
Example
// create the client
let client = Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);
let task = client.create_index("try_make_index", None).await.unwrap();
let index = client.wait_for_task(task, None, None).await.unwrap().try_make_index(&client).unwrap();
// and safely access it
assert_eq!(index.as_ref(), "try_make_index");sourcepub fn unwrap_failure(self) -> MeilisearchError
pub fn unwrap_failure(self) -> MeilisearchError
Unwrap the MeilisearchError from a Self::Failed Task.
Will panic if the task was not Self::Failed.
Example
let task = client.create_index("unwrap_failure", None).await.unwrap();
let task = client
.create_index("unwrap_failure", None)
.await
.unwrap()
.wait_for_completion(&client, None, None)
.await
.unwrap();
assert!(task.is_failure());
let failure = task.unwrap_failure();
assert_eq!(failure.error_code, ErrorCode::IndexAlreadyExists);sourcepub fn is_failure(&self) -> bool
pub fn is_failure(&self) -> bool
Returns true if the Task is Self::Failed.
Example
let task = client.create_index("is_failure", None).await.unwrap();
let task = client
.create_index("is_failure", None)
.await
.unwrap()
.wait_for_completion(&client, None, None)
.await
.unwrap();
assert!(task.is_failure());sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns true if the Task is Self::Succeeded.
Example
let task = client
.create_index("is_success", None)
.await
.unwrap()
.wait_for_completion(&client, None, None)
.await
.unwrap();
assert!(task.is_success());sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Returns true if the Task is pending (Self::Enqueued or Self::Processing).
Example
let task_info = client
.create_index("is_pending", None)
.await
.unwrap();
let task = client.get_task(task_info).await.unwrap();
assert!(task.is_pending());Trait Implementations§
source§impl<'de> Deserialize<'de> for Task
impl<'de> Deserialize<'de> for Task
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more