调用CreateJob创建任务。
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
请求参数
名称 | 类型 | 是否必选 | 示例值 | 描述 |
---|---|---|---|---|
Action | String | 是 | CreateJob |
系统规定参数。取值:CreateJob。 |
ExecuteMode | String | 是 | standalone |
任务执行模式,目前支持以下几种任务执行模式:
|
GroupId | String | 是 | testSchedulerx.defaultGroup |
应用ID,在控制台的应用管理页面中获取。 |
JobType | String | 是 | Java |
任务类型,目前支持以下几种任务类型:
|
Name | String | 是 | helloworld |
任务名。 |
Namespace | String | 是 | adcfc35d-e2fe-4fe9-bbaa-20e90ffc**** |
命名空间ID,在控制台的命名空间页面中获取。 |
RegionId | String | 是 | cn-hangzhou |
地域ID。 |
TimeType | Integer | 是 | 1 |
时间类型,目前支持以下几种时间类型:
|
Description | String | 否 | Test |
任务描述。 |
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。 |
TimeExpression | String | 否 | 0 0/10 * * * ? |
时间表达式,根据选择的时间类型设置时间表达式。
|
Calendar | String | 否 | 暂不支持,不用填写 |
cron类型可以选择填写自定义日历。 |
DataOffset | Integer | 否 | 2400 |
cron类型可以选择时间偏移,单位s。 |
TimeoutEnable | Boolean | 否 | false |
超时报警开关。取值如下:
|
Timeout | Long | 否 | 7200 |
超时阈值,单位s,默认值7200。 |
TimeoutKillEnable | Boolean | 否 | false |
超时终止开关。取值如下:
|
FailEnable | Boolean | 否 | 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 |
创建任务是否成功。取值如下:
|
示例
请求示例
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));
}
}
}