全部产品

获取作业列表

更新时间:2018-11-19 21:03:26

接口

listJobs

参数

参数 类型 是否必选 说明
marker String 本页起始资源标识符。默认为空字符串。
maxItemCount int 返回条数,最大取值200,默认200

返回值

成功后返回一个 ListJobsResponse 实例可以通过这个实例的 getJobList() 方法,拿到List<Job>对象。如果失败,抛出异常: 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. import java.util.ArrayList;
  6. import java.util.List;
  7. public class ListJobs {
  8. static String ACCESS_KEY_ID = "xxx"; //这里填写您的 AccessKeyId
  9. static String ACCESS_KEY_SECRET = "xxx"; //这里填写您的 AccessKeySecret
  10. static String REGION_ID = "cn-xxx"; //这里填写 region
  11. public static void main(String[] args) {
  12. String marker = ""; //上次listJobs返回的nextMarker,第一次查询不用填。
  13. int maxItemCount = 100; //最大100,默认50
  14. BatchCompute client = new BatchComputeClient(REGION_ID, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
  15. try{
  16. List<Job> list = new ArrayList<>();
  17. do{
  18. ListJobsResponse response = client.listJobs(marker, maxItemCount);
  19. //成功
  20. list.addAll(response.getItems());
  21. //下一页的marker,查询下一页的时候,需要带上这个参数
  22. marker = response.getNextMarker();
  23. }while(marker!=null && !marker.equals(""));
  24. for (Job job: list){
  25. System.out.println("jobId: " + job.getId());
  26. System.out.println("jobName: " + job.getName());
  27. }
  28. }catch(ClientException e){
  29. e.printStackTrace();
  30. //失败
  31. }
  32. }
  33. }

执行结果:

  1. {
  2. jobId: job-000000005BE3E897000007FA00106E5F
  3. jobName: test
  4. jobId: job-000000005BE3E897000007FA00106EF8
  5. jobName: test3
  6. jobId: job-000000005BE3E897000007FA0010708B
  7. jobName: test3
  8. jobId: job-000000005BE3E897000007FA0010785C
  9. jobName: test3
  10. jobId: job-000000005BE3E897000007FA001078C1
  11. jobName: test3
  12. jobId: job-000000005BE3E897000007FA00107AB6
  13. jobName: test3
  14. jobId: job-000000005BE3E897000007FA00114EE9
  15. jobName: javaSdkJob
  16. }