创建任务并返回任务ID。
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
授权信息
下表是API对应的授权信息,可以在RAM权限策略语句的Action元素中使用,用来给RAM用户或RAM角色授予调用此API的权限。具体说明如下:
- 操作:是指具体的权限点。
- 访问级别:是指每个操作的访问级别,取值为写入(Write)、读取(Read)或列出(List)。
- 资源类型:是指操作中支持授权的资源类型。具体说明如下:- 对于必选的资源类型,用前面加 * 表示。
- 对于不支持资源级授权的操作,用全部资源表示。
 
- 条件关键字:是指云产品自身定义的条件关键字。
- 关联操作:是指成功执行操作所需要的其他权限。操作者必须同时具备关联操作的权限,操作才能成功。
| 操作 | 访问级别 | 资源类型 | 条件关键字 | 关联操作 | 
|---|---|---|---|---|
| edas:CreateSchedulerxJobCreate | create | *全部资源 * | 
 | 无 | 
请求参数
| 名称 | 类型 | 必填 | 描述 | 示例值 | 
|---|---|---|---|---|
| RegionId | string | 是 | 地域 ID。 | cn-hangzhou | 
| Namespace | string | 是 | 命名空间 ID,在控制台的命名空间页面中获取。 | adcfc35d-e2fe-4fe9-bbaa-20e90ffc**** | 
| NamespaceSource | string | 否 | 特殊第三方才需要填写。 | schedulerx | 
| GroupId | string | 是 | 应用 ID,在控制台的应用管理页面中获取。 | testSchedulerx.defaultGroup | 
| JobType | string | 是 | 任务类型,目前支持以下几种任务类型: 
 枚举值: 
 | java | 
| Name | string | 是 | 任务名。 | helloworld | 
| Description | string | 否 | 任务描述。 | Test | 
| ExecuteMode | string | 是 | 任务执行模式,目前支持以下几种任务执行模式: 
 枚举值: 
 | standalone | 
| ClassName | string | 否 | 任务接口类完整路径。 当您选择 Java 任务类型时,才有该字段且必须填写完整路径。 | com.alibaba.schedulerx.test.helloworld | 
| Content | string | 否 | 
 | echo 'hello' | 
| Parameters | string | 否 | 用户自定义参数,运行时可以获取。 | test | 
| MaxConcurrency | integer | 否 | 最大同时运行实例数量,默认值为 1,即上次触发没有运行结束,即使到了运行时刻也不会进行下次触发。 | 1 | 
| MaxAttempt | integer | 否 | 错误最大重试次数,根据业务需求填写,默认值为 0。 | 0 | 
| AttemptInterval | integer | 否 | 错误重试间隔,单位 s,默认值为 30。 | 30 | 
| PageSize | integer | 否 | 并行网格任务高级配置,单次拉取子任务数,默认值为 100。 | 100 | 
| ConsumerSize | integer | 否 | 并行网格任务高级配置,单机单次触发执行线程数,默认值为 5。 | 5 | 
| QueueSize | integer | 否 | 并行网格任务高级配置,子任务队列缓存上限,默认值为 10000。 | 10000 | 
| DispatcherSize | integer | 否 | 并行网格任务高级配置,子任务分发线程数,默认值为 5。 | 5 | 
| TimeType | integer | 是 | 时间类型,目前支持以下几种时间类型: 
 | 1 | 
| TimeExpression | string | 否 | 时间表达式,根据选择的时间类型设置时间表达式。 
 | 0 0/10 * * * ? | 
| Calendar | string | 否 | cron 类型可以选择填写自定义日历。 | 暂不支持,不用填写 | 
| DataOffset | integer | 否 | cron 类型可以选择时间偏移,单位 s。 | 2400 | 
| Timezone | string | 否 | 时区 | GMT+8 | 
| TimeoutEnable | boolean | 否 | 超时报警开关。取值如下: 
 | false | 
| Timeout | long | 否 | 超时阈值,单位 s,默认值 7200。 | 7200 | 
| TimeoutKillEnable | boolean | 否 | 超时终止开关。取值如下: 
 | false | 
| FailEnable | boolean | 否 | 失败报警开关。取值如下: 
 | false | 
| FailTimes | integer | 否 | 连续失败报警次数 | 2 | 
| MissWorkerEnable | boolean | 否 | 是否开启无可用机器报警。 
 | false | 
| SuccessNoticeEnable | boolean | 否 | 成功通知开关 | false | 
| SendChannel | string | 否 | 告警通知渠道。 
 | sms | 
| TaskMaxAttempt | integer | 否 | 并行网格任务高级配置,子任务失败重试次数 ,默认值为 0。 | 0 | 
| TaskAttemptInterval | integer | 否 | 并行网格任务高级配置,子任务失败重试间隔,默认值为 0。 | 0 | 
| ContactInfo | array<object> | 否 | 任务联系人信息。 注意  该字段已废弃 | 1 | 
| object | 否 | 任务联系人信息。 | ||
| UserPhone | string | 否 | 报警接收手机号。 | 1381111**** | 
| UserName | string | 否 | 报警联系人姓名。 | 张三 | 
| UserMail | string | 否 | 报警联系人邮箱。 | test***@***.com | 
| Ding | string | 否 | 报警联系人钉钉群机器人 webhook 地址,参考文档:钉钉开发文档。 | https://oapi.dingtalk.com/robot/send?access_token=********** | 
| Status | integer | 否 | 0:禁用,1:启用,默认启用。 | 1 | 
| XAttrs | string | 否 | 如果是 k8s 任务类型,需要配置该参数 Job 任务:{"resource":"job"} Shell 任务:{"image":"busybox","resource":"shell"} | {"resource":"job"} | 
| Priority | integer | 否 | 任务优先级。取值如下: 
 | 5 | 
返回参数
示例
正常返回示例
JSON格式
{
  "Code": 200,
  "Message": "message",
  "RequestId": "39090022-1F3B-4797-8518-6B61095F1AF0",
  "Success": true,
  "Data": {
    "JobId": 92583
  }
}错误码
访问错误中心查看更多错误码。
变更历史
| 变更时间 | 变更内容概要 | 操作 | 
|---|---|---|
| 2024-10-21 | OpenAPI 返回结构发生变更 | 查看变更详情 | 
| 2023-03-30 | API 内部配置变更,不影响调用 | 查看变更详情 | 
| 2022-12-26 | API 内部配置变更,不影响调用 | 查看变更详情 | 
| 2022-09-29 | API 内部配置变更,不影响调用 | 查看变更详情 | 
| 2022-09-27 | OpenAPI 入参发生变更 | 查看变更详情 | 
| 2022-06-13 | OpenAPI 入参发生变更 | 查看变更详情 | 
创建 Java 任务
package com.alibaba.schedulerx.pop;
import java.util.ArrayList;
import java.util.List;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobRequest;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobRequest.ContactInfo;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobResponse;
public class CreateJavaJob {
    public static void main(String[] args) throws Exception {
     //  OpenAPI 的接入点,可查看产品支持的地域列表或根据购买产品的地域填写。
        String regionId = "cn-shanghai";
        //鉴权使用的 AccessKey ID,由阿里云官网控制台获取。
        String accessKeyId = "<yourAccessKeyId>";
        //鉴权使用的 AccessKey Secret,由阿里云官网控制台获取
        String accessKeySecret = "<yourAccessKeySecret>";
        //产品名称。
        String productName ="schedulerx2";
        //对照支持地域列表选择 Domain 填写。
        String domain ="schedulerx.cn-shanghai.aliyuncs.com";
        //构建 OpenAPI 客户端。
        DefaultProfile.addEndpoint(regionId, productName, domain);
        DefaultProfile defaultProfile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(defaultProfile);
        
        CreateJobRequest request = new CreateJobRequest();
        request.setJobType("java");
        request.setExecuteMode("standalone");
        request.setDescription("test");
        request.setName("helloworld");
        request.setClassName("com.alibaba.schedulerx.test.helloworld");
        request.setTimeType(1);
        request.setTimeExpression("0 0/10 * * * ?");
        request.setNamespace("xxxxx");
        request.setGroupId("xxxxxxx");
        // monitor
        request.setTimeoutEnable(true);
        request.setTimeoutKillEnable(true);
        request.setFailEnable(true);
        request.setTimeout(12300L);
        List<ContactInfo> contactInfosList = new ArrayList<>();
        ContactInfo contactInfo1 = new ContactInfo();
        contactInfo1.setUserName("userA");
        contactInfo1.setUserPhone("1381111****");
        ContactInfo contactInfo2 = new ContactInfo();
        contactInfo2.setUserName("userB");
        contactInfo2.setUserPhone("1382222****");
        contactInfosList.add(contactInfo1);
        contactInfosList.add(contactInfo2);
        request.setContactInfos(contactInfosList);
        // attrs
        //request.setQueueSize(123);
        request.setTaskMaxAttempt(1);
        request.setTaskAttemptInterval(100);
        CreateJobResponse response = client.getAcsResponse(request);
        if (response.getSuccess()) {
            System.out.println("jobId=" + response.getData().getJobId());
        } else {
            System.out.println(response.getMessage());
        }
    }
}
创建 HTTP 任务
package com.alibaba.schedulerx.pop;
import com.alibaba.schedulerx.common.domain.HttpAttribute;
import com.alibaba.schedulerx.common.util.JsonUtil;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobRequest;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobResponse;
public class CreateHttpJob {
    public static void main(String[] args) throws Exception {
     // OpenAPI 的接入点,具体查看支持地域列表或根据购买地域填写。
        String regionId = "cn-shanghai";
        //鉴权使用的 AccessKey ID,由阿里云官网控制台获取。
        String accessKeyId = "<yourAccessKeyId>";
        //鉴权使用的 AccessKey Secret,由阿里云官网控制台获取。
        String accessKeySecret = "<yourAccessKeySecret>";
        //产品名称。
        String productName ="schedulerx2";
        //对照支持地域列表选择 Domain 填写。
        String domain ="schedulerx.cn-shanghai.aliyuncs.com";
        //构建 OpenAPI 客户端。
        DefaultProfile.addEndpoint(regionId, productName, domain);
        DefaultProfile defaultProfile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(defaultProfile);
        
        CreateJobRequest request = new CreateJobRequest();
        request.setNamespace("xxxxxxxx");
        request.setGroupId("xxxxxx");
        request.setJobType("http");
        request.setName("testHttpJob");
        request.setDescription("testHttpJob");
        request.setTimeType(1);
        request.setTimeExpression("20 0/5 * * * ?");
        request.setExecuteMode("standalone");
        HttpAttribute httpAttribute = new HttpAttribute();
        httpAttribute.setUrl("http://192.168.0.0:8080/test");
        httpAttribute.setMethod("GET");
        httpAttribute.setTimeout(10); //单位秒
        httpAttribute.setRespKey("code");
        httpAttribute.setRespValue("200");
        request.setContent(JsonUtil.toJson(httpAttribute));
        //POST 参数,格式 key1=value1&key2=value2。
        request.setParameters("key1=value1&key2=value2");   
        
        //发送请求。
        CreateJobResponse response = client.getAcsResponse(request);
        if (!response.getSuccess()) {
            System.out.println(response.getMessage());
            System.out.println("createApp: "+response.getRequestId());
        } else {
            System.out.println(JsonUtil.toJson(response));
        }
    }
    
}
创建一次性任务
package com.alibaba.schedulerx.pop;
import java.util.ArrayList;
import java.util.List;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobRequest;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobRequest.ContactInfo;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobResponse;
public class CreateJavaJob {
    public static void main(String[] args) throws Exception {
     // OpenAPI 的接入点,可查看产品支持的地域列表或根据购买产品的地域填写。
        String regionId = "cn-shanghai";
        //鉴权使用的 AccessKey ID,由阿里云官网控制台获取
        String accessKeyId = "xxxxxx";
        //鉴权使用的 AccessKey Secret,由阿里云官网控制台获取
        String accessKeySecret = "xxxxxxxx";
        //产品名称
        String productName ="schedulerx2";
        //对照支持地域列表选择 Domain 填写
        String domain ="schedulerx.cn-shanghai.aliyuncs.com";
        //构建 OpenAPI 客户端
        DefaultProfile.addEndpoint(regionId, productName, domain);
        DefaultProfile defaultProfile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(defaultProfile);
        
        CreateJobRequest request = new CreateJobRequest();
        request.setJobType("java");
        request.setExecuteMode("standalone");
        request.setDescription("test");
        request.setName("helloworld");
        request.setClassName("com.alibaba.schedulerx.test.helloworld");
        request.setTimeType(5);
        request.setTimeExpression("2021-12-30 12:12:12");
        request.setNamespace("xxxxxx");
        request.setGroupId("xxxxxxx");
        // 报警监控
        request.setTimeoutEnable(true);
        request.setTimeoutKillEnable(true);
        request.setFailEnable(true);
        request.setTimeout(12300L);
        // 高级配置
        request.setMaxAttempt(3);
        request.setAttemptInterval(30);
        CreateJobResponse response = client.getAcsResponse(request);
        if (response.getSuccess()) {
            System.out.println("jobId=" + response.getData().getJobId());
        } else {
            System.out.println(response.getMessage());
        }
    }
    
}
