# IRPCBackgroundOperationsAdmin.WaitForAsyncTaskCompletion

Location: [gRPC API](https://developer.m-files.com/APIs/gRPC-API/index.md) > [Administration API](https://developer.m-files.com/APIs/gRPC-API/admin/index.md) > [Background operations](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCBackgroundOperationsAdmin/index.md)

HTML version: https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCBackgroundOperationsAdmin/WaitForAsyncTaskCompletion/

Badges: `Administration API / specialized` `admin` `session` `idempotent`

Waits until the given asynchronous tasks have finished, then optionally returns a list of tasks.

- **Service:** [Background operations](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCBackgroundOperationsAdmin/index.md) `MFiles.IRPCBackgroundOperationsAdmin`
- **gRPC method:** `/MFiles.IRPCBackgroundOperationsAdmin/WaitForAsyncTaskCompletion`
- **HTTP (mf-http-grpc):** `POST /grpc/v1/wait-for-async-task-completion`
- **Request:** [`WaitForAsyncTaskCompletionRequest`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCBackgroundOperationsAdmin/WaitForAsyncTaskCompletion/index.md#request)
- **Response:** [`WaitForAsyncTaskCompletionResponse`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCBackgroundOperationsAdmin/WaitForAsyncTaskCompletion/index.md#response)
- **Book and level:** Administration API, specialized
- **Kind:** admin
- **Session:** Required: the session ID from LogIn in the mfiles-session-id-bin metadata.
- **Idempotent:** yes
- **Returns metadata structure version:** no
- **Streaming:** none (unary)

<a id="remarks"></a>

## Remarks

- **Blocks without a server-side time limit**: the server checks the tasks every two seconds
  until all are done. Set a deadline on the call. The wait is cancelled with an error when the
  server shuts down or the vault goes offline.
- A task counts as done when it has completed successfully or was cancelled. When a task was
  merged into a newer task, the server waits for the newer one. When a task fails, the call fails
  with the task's error. An unknown ID fails with "Not found. <id>".
- At most 50 tasks per call, and `tasks_request.max_count` at most 50; more fail with "The
  parameter is incorrect.".
- `tasks_request` is run after the wait, so its result lists the tasks that are still queued or
  running at that point. See the waiting recipe in the service overview.
- Requires a vault session and the vault right `change_metadata_structure`.

<a id="request"></a>

## Request: WaitForAsyncTaskCompletionRequest

A structure that specifies the request type for the WaitForAsyncTaskCompletion method.

> Nested message fields are expanded to depth 3; follow a type link for deeper levels and for the type's own page.

| Field | Type | Description |
|---|---|---|
| `obsolete_async_task` | `int64` | Obsolete. Set 0; a non-zero ID is waited for in addition to `async_tasks`. |
| `tasks_request` | [`GetAsyncTasksRangeRequest`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.GetAsyncTasksRangeRequest/index.md) | Optional. If set, the response carries the result of this [GetAsyncTasksRange](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCBackgroundOperationsAdmin/GetAsyncTasksRange/index.md) request, run after the wait. `max_count` must be at most 50. |
| `tasks_request.async_task_start` | `int64` | The first task ID to return, or -1 to start from the newest (`latest` true) or the oldest (`latest` false) task. |
| `tasks_request.max_count` | `uint32` | The maximum number of tasks to return. 0 returns nothing. |
| `tasks_request.latest` | `bool` | True to go from `async_task_start` towards older tasks (descending IDs), false to go towards newer tasks (ascending IDs). |
| `tasks_request.filters` | `uint32` | The task states to include, as a sum of bit values: 1 queued, 2 running, 4 completed successfully, 8 cancelled, 16 failed. 0 includes all tasks. |
| `async_tasks[]` | repeated `int64` | The IDs of the tasks to wait for, at most 50. |

<a id="response"></a>

## Response: WaitForAsyncTaskCompletionResponse

A structure that specifies the response type for the WaitForAsyncTaskCompletion method.

> Nested message fields are expanded to depth 3; follow a type link for deeper levels and for the type's own page.

| Field | Type | Description |
|---|---|---|
| `tasks_response` | [`GetAsyncTasksRangeResponse`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.GetAsyncTasksRangeResponse/index.md) | The result of `tasks_request`; unset if the request had none. |
| `tasks_response.async_tasks[]` | repeated [`AsyncTask`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.AsyncTask/index.md) | The tasks, in the order given by `latest`. |
| `tasks_response.async_tasks[].id` | `int64` | Task ID. |
| `tasks_response.async_tasks[].type` | `string` | Task type name. |
| `tasks_response.async_tasks[].definition` | `string` | The display string of the task definition. |
| `tasks_response.async_tasks[].is_running` | `bool` | True if the task is currently running. |
| `tasks_response.async_tasks[].last_run_started_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | The last time the task ran started. Zero to indicate that the task has never run (or is still running for the first time). |
| `tasks_response.async_tasks[].last_run_ended_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | The last time the task ran ended. Zero to indicate that the task has never run (or is still running for the first time). |
| `tasks_response.async_tasks[].last_run_succeeded` | `bool` | True if the last run was successful, false otherwise. |
| `tasks_response.async_tasks[].last_run_errors` | `string` | Error string from the last run (if any). |
| `tasks_response.async_tasks[].canceled` | `bool` | True if the task is canceled. |
| `tasks_response.async_tasks[].progress_info` | `string` | The progress info string of the task. |
| `tasks_response.async_tasks[].output_info` | `string` | The output info string of the task. |
