获取任务信息

接口

getTask

参数

参数 类型 是否必需 说明
jobId String 作业ID
taskName String 任务名称

返回值

成功后返回一个 GetTaskResponse 实例, 可以通过这个实例的 getTask() 方法,获取 Task 对象。如果失败,抛出异常: ClientException

例子

Java 源码

  1. import com.aliyuncs.batchcompute.main.v20151111.*;
  2. import com.aliyuncs.batchcompute.model.v20151111.*;
  3. import com.aliyuncs.batchcompute.pojo.v20151111.*;
  4. import com.aliyuncs.exceptions.ClientException;
  5. public class GetTask {
  6. static String ACCESS_KEY_ID = "xxx"; //这里填写您的 AccessKeyId
  7. static String ACCESS_KEY_SECRET = "xxx"; //这里填写您的 AccessKeySecret
  8. static String REGION_ID = "cn-xxx"; //这里填写 region
  9. static String jobId = "job-000000005BE3E897000007FA00114EE9";
  10. static String taskName = "javaSdkTask";
  11. public static void main(String[] args) {
  12. BatchCompute client = new BatchComputeClient(REGION_ID, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
  13. try{
  14. GetTaskResponse response = client.getTask(jobId, taskName);
  15. //成功
  16. Task task = response.getTask();
  17. System.out.println("taskName: " + task.getTaskName());
  18. System.out.println("taskState: " + task.getState());
  19. System.out.println("taskTime: " + task.getStartTime());
  20. System.out.println("RequestId: " + response.getRequestId());
  21. System.out.println("StatusCode: " + response.getStatusCode());
  22. }catch(ClientException e){
  23. e.printStackTrace();
  24. //失败
  25. }
  26. }
  27. }

执行结果:

  1. {
  2. taskName: javaSdkTask
  3. taskState: Stopped
  4. taskTime: null
  5. RequestId: null
  6. StatusCode: 200
  7. }