调用CreateJob创建任务。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

请求参数

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

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

ExecuteMode String standalone

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

  • 单机运行:standalone
  • 广播运行:broadcast
  • 并行计算:parallel
  • 内存网格:grid
  • 网格计算:batch
  • 分片运行:sharding
GroupId String testSchedulerx.defaultGroup

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

JobType String Java

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


- **java**
- **python**
- **shell**
- **go**
- **http**
- **nodejs**
Name String helloworld

任务名。

Namespace String adcfc35d-e2fe-4fe9-bbaa-20e90ffc****

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

RegionId String cn-hangzhou

地域ID。

TimeType Integer 1

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

  • cron:1
  • fixed_rate:3
  • second_delay:4
  • api:100
Description String Test

任务描述。

Content String echo 'hello'

任务类型选择为pythonshellgo时,必填的脚本代码内容。

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。

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。

ContactInfo.N.UserName String userA

报警联系人姓名。

ContactInfo.N.UserPhone String 1381111****

报警接收手机号。

NamespaceSource String schedulerx

特殊第三方才需要填写。

TaskMaxAttempt Integer 0

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

TaskAttemptInterval Integer 0

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

返回数据

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

返回码

Data Struct

任务详细信息

JobId Long 92583

任务ID

Message String groupid not exist groupId: testSchedulerx.defaultGroup namespace: adcfc35d-e2fe-4fe9-bbaa-20e90ffc****

错误信息,仅错误时返回错误信息。

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

请求唯一ID

Success Boolean true

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

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

示例

请求示例

http(s)://[Endpoint]/?Action=CreateJob
&ExecuteMode=standalone
&GroupId=testSchedulerx.defaultGroup
&JobType=java
&Name=helloworld
&Namespace=adcfc35d-e2fe-4fe9-bbaa-20e90ffc****
&RegionId=cn-hangzhou
&TimeType=1
&<公共请求参数>

正常返回示例

XML格式

<CreateJobResponse>
  <RequestId>39090022-1F3B-4797-8518-6B61095F1AF0</RequestId>
  <Message>groupid not exist groupId: testSchedulerx.defaultGroup namespace: adcfc35d-e2fe-4fe9-bbaa-20e90ffc****</Message>
  <Data>
        <JobId>92583</JobId>
  </Data>
  <Code>200</Code>
  <Success>true</Success>
</CreateJobResponse>

JSON格式

{
    "RequestId": "39090022-1F3B-4797-8518-6B61095F1AF0",
    "Message": "groupid not exist groupId: testSchedulerx.defaultGroup namespace: adcfc35d-e2fe-4fe9-bbaa-20e90ffc****",
    "Data": {
        "JobId": 92583
    },
    "Code": 200,
    "Success": true
}

创建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";
        //鉴权使用的AccessKeyId,由阿里云官网控制台获取。
        String accessKeyId = "<yourAccessKeyId>";
        //鉴权使用的AccessKeySecret,由阿里云官网控制台获取。
        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";
        //鉴权使用的AccessKeyId,由阿里云官网控制台获取。
        String accessKeyId = "<yourAccessKeyId>";
        //鉴权使用的AccessKeySecret,由阿里云官网控制台获取。
        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));
        }
    }
    
}