작업 취소 API (Cancel Tasks API)
Cancel Tasks API는 작업(task)을 취소해서 클러스터에서 실행을 중지시켜요. 모든 작업을 취소할 수 있는 건 아닙니다. 작업이 취소 가능한지 확인하려면 Cancel Tasks API 응답의 cancellable 필드를 확인하세요.
출처: OpenSearch 문서
본문
Endpoints
POST /_tasks/_cancel
POST /_tasks/{task_id}/_cancel
Path parameters
다음 표는 사용 가능한 경로 파라미터를 보여줘요. 모든 경로 파라미터는 선택사항이에요.
| Parameter | Data type | Description | | task_id | String | The task ID. |
Query parameters
다음 표는 사용 가능한 쿼리 파라미터를 보여줘요. 모든 쿼리 파라미터는 선택사항이에요.
| Parameter | Data type | Description | | actions | List or String | A comma-separated list of actions that should be returned. Keep empty to return all. | | nodes | List | A comma-separated list of node IDs or names used to limit the returned information. Use _local to return information from the node you're connecting to, specify the node name to get information from a specific node, or keep the parameter empty to get information from all nodes. | | parent_task_id | String | Returns tasks with a specified parent task ID (node_id:task_number). Keep empty or set to -1 to return all. | | wait_for_completion | Boolean | Waits for the matching task to complete. When true, the request is blocked until the task has completed. (Default: false) |
Example request
다음 요청은 현재 opensearch-node1과 opensearch-node2에서 실행 중인 모든 작업을 취소해요.
REST Python
POST /_tasks/_cancel?nodes=opensearch-node1,opensearch-node2
Copy Copy as cURL
response = client.tasks.cancel(
params = { "nodes": "opensearch-node1,opensearch-node2" }
)
Copy
Example response
다음 응답은 노드 실패 없이 bulk 쓰기와 update 작업이 취소됐음을 보여주고, 취소된 작업에 대한 추가 정보를 제공해요.
{
"node_failures": [],
"nodes": {
"JzrCxdtFTCO_RaINw8ckNA": {
"name": "opensearch-node1",
"transport_address": "127.0.0.1:9300",
"host": "127.0.0.1",
"ip": "127.0.0.1:9300",
"roles": [
"data",
"ingest",
"cluster_manager",
"remote_cluster_client"
],
"attributes": {},
"tasks": {
"JzrCxdtFTCO_RaINw8ckNA:54": {
"node": "JzrCxdtFTCO_RaINw8ckNA",
"id": 54,
"type": "transport",
"action": "indices:data/write/bulk",
"status": "cancelled",
"description": "bulk request to [test_index]",
"start_time_in_millis": 1625145678901,
"running_time_in_nanos": 2345678,
"cancellable": true,
"cancelled": true
}
}
},
"K8iyDdtGQCO_SbJNw9dkMB": {
"name": "opensearch-node2",
"transport_address": "127.0.0.1:9301",
"host": "127.0.0.1",
"ip": "127.0.0.1:9301",
"roles": [
"data",
"ingest",
"master",
"remote_cluster_client"
],
"attributes": {},
"tasks": {
"K8iyDdtGQCO_SbJNw9dkMB:78": {
"node": "K8iyDdtGQCO_SbJNw9dkMB",
"id": 78,
"type": "transport",
"action": "indices:data/write/update",
"status": "cancelled",
"description": "updating document in [another_index]",
"start_time_in_millis": 1625145679012,
"running_time_in_nanos": 1234567,
"cancellable": true,
"cancelled": true
}
}
}
}
}
Required permissions
Security 플러그인을 사용한다면 적절한 권한(cluster:admin/tasks/cancel)을 가지고 있는지 확인하세요.