Cancels up to 50 jobs in an Batch job queue. This is a bulk version of CancelJob. Jobs that are in a SUBMITTED, PENDING, or RUNNABLE state are cancelled and the job status is updated to FAILED.
A PENDING job is cancelled after all dependency jobs are completed. Therefore, it might take longer than expected to cancel a job in PENDING status.
When you try to cancel an array parent job in PENDING, Batch attempts to cancel all child jobs. The array parent job is cancelled when all child jobs are completed.
Jobs that progressed to the STARTING or RUNNING state aren't cancelled. These jobs must be terminated with the TerminateJob or TerminateJobs operation.
Batch reports the result for each job individually in the response. Jobs that were processed successfully are reported in the successful list. Jobs that encountered errors are reported in the errors list. The response returns an HTTP status code of 200 even when some jobs encountered errors, so check the errors list. Jobs that can't be found are treated as successfully processed.
This operation requires batch:CancelJob permission for each job in the request. There is no separate batch:CancelJobs IAM action. If a caller's IAM policy grants batch:CancelJob, they can use both the singular CancelJob and bulk CancelJobs operations.
Parameters:
-
jobs
(Optional[StringList], default:
None
)
–
An array of up to 50 Batch job IDs of the jobs to cancel.
-
reason
(Optional[String], default:
None
)
–
A message to attach to the job that explains the reason for cancelling it. This message is returned by future DescribeJobs operations on the job. It is also recorded in the Batch activity logs.
This parameter has a limit of 1024 characters.
Raises:
-
ClientException
–
These errors are usually caused by a client action. One example cause is using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Another cause is specifying an identifier that's not valid.
-
ServerException
–
These errors are usually caused by a server issue.
-
UnknownServiceError
–
The service returned an error code this client does not model.
Examples:
To cancel multiple jobs
This example cancels the jobs with the specified job IDs.
>>> client.cancel_jobs(jobs=['1d828f65-7a4d-42e8-996d-3b900ed59dc4', 'b3d0f26e-6d3a-4a5b-9c2e-7f4a1b2c3d4e'], reason='Cancelling jobs.')
Source code in docs_src/capo_batch/_services/batch.py
| def cancel_jobs(
self,
*,
config_overrides: Optional[BatchClientConfig] = None,
jobs: Optional["capo_batch.types.string_list.StringList"] = None,
reason: Optional["capo_batch.types.string.String"] = None,
) -> "capo_batch.types.cancel_jobs_response.CancelJobsResponse":
"""<p>Cancels up to 50 jobs in an Batch job queue. This is a bulk version of <a>CancelJob</a>. Jobs that are in a <code>SUBMITTED</code>, <code>PENDING</code>, or <code>RUNNABLE</code> state are cancelled and the job status is updated to <code>FAILED</code>.</p> <note> <p>A <code>PENDING</code> job is cancelled after all dependency jobs are completed. Therefore, it might take longer than expected to cancel a job in <code>PENDING</code> status.</p> <p>When you try to cancel an array parent job in <code>PENDING</code>, Batch attempts to cancel all child jobs. The array parent job is cancelled when all child jobs are completed.</p> </note> <p>Jobs that progressed to the <code>STARTING</code> or <code>RUNNING</code> state aren't cancelled. These jobs must be terminated with the <a>TerminateJob</a> or <a>TerminateJobs</a> operation.</p> <p>Batch reports the result for each job individually in the response. Jobs that were processed successfully are reported in the <code>successful</code> list. Jobs that encountered errors are reported in the <code>errors</code> list. The response returns an HTTP status code of <code>200</code> even when some jobs encountered errors, so check the <code>errors</code> list. Jobs that can't be found are treated as successfully processed.</p> <important> <p>This operation requires <code>batch:CancelJob</code> permission for each job in the request. There is no separate <code>batch:CancelJobs</code> IAM action. If a caller's IAM policy grants <code>batch:CancelJob</code>, they can use both the singular <a>CancelJob</a> and bulk <code>CancelJobs</code> operations.</p> </important>
Args:
jobs: <p>An array of up to 50 Batch job IDs of the jobs to cancel.</p>
reason: <p>A message to attach to the job that explains the reason for cancelling it. This message is returned by future <a>DescribeJobs</a> operations on the job. It is also recorded in the Batch activity logs.</p> <p>This parameter has a limit of 1024 characters.</p>
Raises:
capo_batch.errors.client_exception.ClientException: <p>These errors are usually caused by a client action. One example cause is using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Another cause is specifying an identifier that's not valid.</p>
capo_batch.errors.server_exception.ServerException: <p>These errors are usually caused by a server issue.</p>
capo_batch.errors.UnknownServiceError: The service returned an error code this client does not model.
Examples:
To cancel multiple jobs
This example cancels the jobs with the specified job IDs.
>>> client.cancel_jobs(jobs=['1d828f65-7a4d-42e8-996d-3b900ed59dc4', 'b3d0f26e-6d3a-4a5b-9c2e-7f4a1b2c3d4e'], reason='Cancelling jobs.')
"""
def _handler(
req: "OperationRequest[capo_batch.types.cancel_jobs_request.CancelJobsRequest]",
) -> OperationResponse[
"capo_batch.types.cancel_jobs_response.CancelJobsResponse"
]:
import capo_batch._operations.aws_batch_v20160810.cancel_jobs
output, http_response = (
capo_batch._operations.aws_batch_v20160810.cancel_jobs.cancel_jobs(
req.options, req.input
)
)
return OperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("CancelJobs")
)
input_: capo_batch.types.cancel_jobs_request.CancelJobsRequest = {}
if jobs is not None:
input_["jobs"] = jobs
if reason is not None:
input_["reason"] = reason
response = execute_pipeline(
OperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
response.response.close()
return response.output
|