创建任务并返回任务ID。

请求参数

名称 类型 是否必选 示例值 描述
Action String 是 CreateJob

系统规定参数。取值:CreateJob。

JobType String 是 java

任务类型,目前支持以下几种任务类型:


- java
- python
- shell
- go
- http
- xxljob
- dataworks
Name String 是 helloworld

任务名。

Description String 否 Test

任务描述。

ExecuteMode String 是 standalone

任务执行模式,目前支持以下几种任务执行模式:

  • 单机运行:standalone
  • 广播运行:broadcast
  • 并行计算:parallel
  • 内存网格:grid
  • 网格计算:batch
  • 分片运行:sharding
Content String 否 echo 'hello'

任务类型选择为python、shell、go时,必填的脚本代码内容。

Parameters String 否 test

用户自定义参数,运行时可以获取。

MaxConcurrency Integer 否 1

最大同时运行实例数量,默认值为1,即上次触发没有运行结束,即使到了运行时刻也不会进行下次触发。

MaxAttempt Integer 否 0

错误最大重试次数,根据业务需求填写,默认值为0。

AttemptInterval Integer 否 30

错误重试间隔,单位s,默认值为30。

ClassName String 否 com.alibaba.schedulerx.test.helloworld

任务接口类完整路径。

当您选择Java任务类型时,才有该字段且必须填写完整路径。

JarUrl String 否 暂不支持,不用填写

上传到OSS的完整路径。

如果选择JAR包运行,可以将相应JAR包上传到OSS的该路径下。

PageSize Integer 否 100

并行网格任务高级配置,单次拉取子任务数,默认值为100。

ConsumerSize Integer 否 5

并行网格任务高级配置,单机单次触发执行线程数,默认值为5。

QueueSize Integer 否 10000

并行网格任务高级配置,子任务队列缓存上限,默认值为10000。

DispatcherSize Integer 否 5

并行网格任务高级配置,子任务分发线程数,默认值为5。

TimeType Integer 是 1

时间类型,目前支持以下几种时间类型:

  • cron:1
  • fixed_rate:3
  • second_delay:4
  • one_time :5
  • api:100
TimeExpression String 否 0 0/10 * * * ?

时间表达式,根据选择的时间类型设置时间表达式。

  • cron:填写标准的cron表达式,支持在线验证。
  • api:无时间表达式。
  • fixed_rate:填写具体固定频率值,单位s。如30表示每隔30s触发一次。
  • second_delay:填写固定延迟多少秒执行一次(1s~60s可选)。
Calendar String 否 暂不支持,不用填写

cron类型可以选择填写自定义日历。

DataOffset Integer 否 2400

cron类型可以选择时间偏移,单位s。

TimeoutEnable Boolean 否 false

超时报警开关。取值如下:

  • true:开启超时报警开关。
  • false:关闭超时报警开关。
Timeout Long 否 7200

超时阈值,单位s,默认值7200。

TimeoutKillEnable Boolean 否 false

超时终止开关。取值如下:

  • true:开启超时终止开关。
  • false:关闭超时终止开关。
FailEnable Boolean 否 false

失败报警开关。取值如下:

  • true:开启失败报警开关。
  • false:关闭失败报警开关。
SendChannel String 否 sms

报警发送形式,目前只支持短信发送报警,默认值sms。

MissWorkerEnable Boolean 否 false

是否开启无可用机器报警。

  • true:开启无可用机器报警开关。
  • false:关闭无可用机器报警开关。
Namespace String 是 adcfc35d-e2fe-4fe9-bbaa-20e90ffc****

命名空间ID,在控制台的命名空间页面中获取。

GroupId String 是 testSchedulerx.defaultGroup

应用ID,在控制台的应用管理页面中获取。

NamespaceSource String 否 schedulerx

特殊第三方才需要填写。

RegionId String 是 cn-hangzhou

地域ID。

TaskMaxAttempt Integer 否 0

并行网格任务高级配置,子任务失败重试次数 ,默认值为0。

TaskAttemptInterval Integer 否 0

并行网格任务高级配置,子任务失败重试间隔,默认值为0。

ContactInfo.N.UserPhone String 否 1381111****

报警接收手机号。

ContactInfo.N.UserName String 否 张三

报警联系人姓名。

ContactInfo.N.UserMail String 否 test***@***.com

报警联系人邮箱。

ContactInfo.N.Ding String 否 https://oapi.dingtalk.com/robot/send?access_token=**********

报警联系人钉钉群机器人webhook地址,参考文档:钉钉开发文档。

Status Integer 否 1

0:禁用,1:启用,默认启用。

XAttrs String 否 {"resource":"job"}

如果是k8s任务类型,需要配置该参数

Job任务:{"resource":"job"}

Shell任务:{"image":"busybox","resource":"shell"}

返回数据

名称 类型 示例值 描述
Code Integer 200

返回码。

Message String message

附加信息。

RequestId String 39090022-1F3B-4797-8518-6B61095F1AF0

请求唯一ID。

Success Boolean true

创建任务是否成功。取值如下:

  • true:创建任务成功。
  • false:创建任务失败。
Data Object

任务详细信息。

JobId Long 92583

任务ID。

示例

请求示例

http(s)://[Endpoint]/?Action=CreateJob
&JobType=java
&Name=helloworld
&Description=Test
&ExecuteMode=standalone
&Content=echo 'hello'
&Parameters=test
&MaxConcurrency=1
&MaxAttempt=0
&AttemptInterval=30
&ClassName=com.alibaba.schedulerx.test.helloworld
&JarUrl=暂不支持,不用填写
&PageSize=100
&ConsumerSize=5
&QueueSize=10000
&DispatcherSize=5
&TimeType=1
&TimeExpression=0 0/10 * * * ?
&Calendar=暂不支持,不用填写
&DataOffset=2400
&TimeoutEnable=false
&Timeout=7200
&TimeoutKillEnable=false
&FailEnable=false
&SendChannel=sms
&MissWorkerEnable=false
&Namespace=adcfc35d-e2fe-4fe9-bbaa-20e90ffc****
&GroupId=testSchedulerx.defaultGroup
&NamespaceSource=schedulerx
&RegionId=cn-hangzhou
&TaskMaxAttempt=0
&TaskAttemptInterval=0
&ContactInfo=[{"UserPhone":"1381111****","UserName":"张三","UserMail":"test***@***.com","Ding":"https://oapi.dingtalk.com/robot/send?access_token=**********"}]
&公共请求参数

正常返回示例

XML格式

HTTP/1.1 200 OK
Content-Type:application/xml

<CreateJobResponse>
    <Code>200</Code>
    <Message>message</Message>
    <RequestId>39090022-1F3B-4797-8518-6B61095F1AF0</RequestId>
    <Success>true</Success>
    <Data>
        <JobId>92583</JobId>
    </Data>
</CreateJobResponse>

JSON格式

HTTP/1.1 200 OK
Content-Type:application/json

{
  "Code" : 200,
  "Message" : "message",
  "RequestId" : "39090022-1F3B-4797-8518-6B61095F1AF0",
  "Success" : true,
  "Data" : {
    "JobId" : 92583
  }
}

创建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());
        }
    }
    
}