Meili.Task (Meili v0.1.3)

Copy Markdown View Source

Manages and monitors asynchronous Meilisearch tasks.

Summary

Functions

Cancels one or more tasks based on filters.

Cancels tasks, raising on error.

Deletes one or more finished tasks based on filters.

Deletes finished tasks, raising on error.

Retrieves details of a single task.

Retrieves details of a single task, raising on error.

Lists all tasks, raising on error.

Waits for a task to succeed or fail, raising a Meili.Error on failure or timeout.

Functions

cancel(client_or_opts \\ nil, opts \\ [])

@spec cancel(Meili.Client.t() | Keyword.t() | nil, Keyword.t()) ::
  {:ok, map()} | {:error, Meili.Error.t()}

Cancels one or more tasks based on filters.

Examples

Meili.Task.cancel(statuses: [:enqueued, :processing])
Meili.Task.cancel(client, index_uids: ["movies"])

cancel!(client_or_opts \\ nil, opts \\ [])

@spec cancel!(Meili.Client.t() | Keyword.t() | nil, Keyword.t()) ::
  map() | no_return()

Cancels tasks, raising on error.

delete(client_or_opts \\ nil, opts \\ [])

@spec delete(Meili.Client.t() | Keyword.t() | nil, Keyword.t()) ::
  {:ok, map()} | {:error, Meili.Error.t()}

Deletes one or more finished tasks based on filters.

Examples

Meili.Task.delete(statuses: [:succeeded, :failed])
Meili.Task.delete(client, uids: [1, 2, 3])

delete!(client_or_opts \\ nil, opts \\ [])

@spec delete!(Meili.Client.t() | Keyword.t() | nil, Keyword.t()) ::
  map() | no_return()

Deletes finished tasks, raising on error.

get(client_or_uid, uid_or_nil \\ nil)

@spec get(Meili.Client.t() | integer() | String.t(), integer() | String.t() | nil) ::
  {:ok, map()} | {:error, Meili.Error.t()}

Retrieves details of a single task.

Examples

Meili.Task.get(12)
Meili.Task.get(client, 12)

get!(client_or_uid, uid_or_nil \\ nil)

@spec get!(Meili.Client.t() | integer() | String.t(), integer() | String.t() | nil) ::
  map() | no_return()

Retrieves details of a single task, raising on error.

list(client_or_opts \\ nil, opts \\ [])

@spec list(Meili.Client.t() | Keyword.t() | nil, Keyword.t()) ::
  {:ok, map()} | {:error, Meili.Error.t()}

Lists all tasks.

Supports options for filtering and pagination. List values are automatically joined as comma-separated strings.

Options

  • limit: Max tasks to return.
  • from: Start task uid.
  • uids: List or comma-separated string of task uids.
  • statuses: List or comma-separated string of statuses.
  • types: List or comma-separated string of types.
  • index_uids / indexUids: List or comma-separated string of index uids.

Examples

Meili.Task.list(statuses: [:succeeded, :failed])
Meili.Task.list(client, limit: 10)

list!(client_or_opts \\ nil, opts \\ [])

@spec list!(Meili.Client.t() | Keyword.t() | nil, Keyword.t()) :: map() | no_return()

Lists all tasks, raising on error.

wait_for_task(client_or_uid, uid_or_opts \\ [], opts \\ [])

@spec wait_for_task(
  Meili.Client.t() | integer() | String.t(),
  integer() | String.t() | Keyword.t(),
  Keyword.t()
) :: {:ok, map()} | {:error, :timeout | Meili.Error.t()}

Waits for a task to succeed or fail.

Options

  • timeout: Maximum time in milliseconds to wait (default: 5000).
  • interval: Milliseconds to sleep between polls (default: 50).

Examples

{:ok, task} = Meili.Task.wait_for_task(12)
{:ok, task} = Meili.Task.wait_for_task(client, 12, timeout: 10_000)

wait_for_task!(client_or_uid, uid_or_opts \\ [], opts \\ [])

@spec wait_for_task!(
  Meili.Client.t() | integer() | String.t(),
  integer() | String.t() | Keyword.t(),
  Keyword.t()
) :: map() | no_return()

Waits for a task to succeed or fail, raising a Meili.Error on failure or timeout.

If the task completes but has a status of "failed", it raises a Meili.Error constructed from the task's inner error.

Examples

task = Meili.Task.wait_for_task!(12)
task = Meili.Task.wait_for_task!(client, 12, timeout: 10_000)