Cancels a job in an Batch job queue. 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. However, the API operation still succeeds, even if no job is cancelled. These jobs must be terminated with the TerminateJob or TerminateJobs operation.
Parameters:
-
job_id
(Optional[String], default:
None
)
–
The Batch job ID of the job 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 a job
This example cancels a job with the specified job ID.
>>> client.cancel_job(reason='Cancelling job.', job_id='1d828f65-7a4d-42e8-996d-3b900ed59dc4')
Source code in docs_src/capo_batch/_services/batch.py
| def cancel_job(
self,
*,
config_overrides: Optional[BatchClientConfig] = None,
job_id: Optional["capo_batch.types.string.String"] = None,
reason: Optional["capo_batch.types.string.String"] = None,
) -> "capo_batch.types.cancel_job_response.CancelJobResponse":
"""<p>Cancels a job in an Batch job queue. 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. However, the API operation still succeeds, even if no job is cancelled. These jobs must be terminated with the <a>TerminateJob</a> or <a>TerminateJobs</a> operation.</p>
Args:
job_id: <p>The Batch job ID of the job 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 a job
This example cancels a job with the specified job ID.
>>> client.cancel_job(reason='Cancelling job.', job_id='1d828f65-7a4d-42e8-996d-3b900ed59dc4')
"""
def _handler(
req: "OperationRequest[capo_batch.types.cancel_job_request.CancelJobRequest]",
) -> OperationResponse[
"capo_batch.types.cancel_job_response.CancelJobResponse"
]:
import capo_batch._operations.aws_batch_v20160810.cancel_job
output, http_response = (
capo_batch._operations.aws_batch_v20160810.cancel_job.cancel_job(
req.options, req.input
)
)
return OperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("CancelJob")
)
input_: capo_batch.types.cancel_job_request.CancelJobRequest = {}
if job_id is not None:
input_["job_id"] = job_id
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
|