文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例。
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
UpdateJobQueue
搭配 AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 UpdateJobQueue
。
動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:
- CLI
-
- AWS CLI
-
更新任務佇列
此範例會停用任務佇列,以便將其刪除。
命令:
aws batch update-job-queue --job-queue GPGPU
--state DISABLED
輸出:
{
"jobQueueArn": "arn:aws:batch:us-east-1:012345678910:job-queue/GPGPU",
"jobQueueName": "GPGPU"
}
- Java
-
- SDK for Java 2.x
-
/**
* Disables the specified job queue asynchronously.
*
* @param jobQueueArn the Amazon Resource Name (ARN) of the job queue to be disabled
* @return a {@link CompletableFuture} that completes when the job queue update operation is complete,
* or completes exceptionally if an error occurs during the operation
*/
public CompletableFuture<Void> disableJobQueueAsync(String jobQueueArn) {
UpdateJobQueueRequest updateRequest = UpdateJobQueueRequest.builder()
.jobQueue(jobQueueArn)
.state(JQState.DISABLED)
.build();
CompletableFuture<UpdateJobQueueResponse> responseFuture = getAsyncClient().updateJobQueue(updateRequest);
return responseFuture.whenComplete((updateResponse, ex) -> {
if (ex != null) {
throw new RuntimeException("Failed to update job queue: " + ex.getMessage(), ex);
}
}).thenApply(updateResponse -> null);
}