All Products
Search
Document Center

SchedulerX:CreateJob

Last Updated:Dec 10, 2024

Creates a job and obtains the job ID.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
edas:CreateSchedulerxJobCreatecreate
*All Resources
*
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
RegionIdstringYes

The region ID.

cn-hangzhou
NamespacestringYes

The namespace ID. You can obtain the namespace ID on the Namespace page in the SchedulerX console.

adcfc35d-e2fe-4fe9-bbaa-20e90ffc****
NamespaceSourcestringNo

The source of the namespace. You must specify this parameter only if the namespace is provided by a third party.

schedulerx
GroupIdstringYes

The application ID. You can obtain the application ID on the Application Management page in the SchedulerX console.

testSchedulerx.defaultGroup
JobTypestringYes

The job type. Valid values:

  • java
  • python
  • shell
  • go
  • http
  • xxljob
  • dataworks
  • k8s
  • springschedule
java
NamestringYes

The job name.

helloworld
DescriptionstringNo

The job description.

Test
ExecuteModestringYes

The execution mode of the job. Valid values:

  • Stand-alone operation
  • Broadcast run
  • Visual MapReduce
  • MapReduce
  • Shard run
standalone
ClassNamestringNo

The full path of the job interface class.

This parameter is available only when you set JobType to java. You must enter a full path.

com.alibaba.schedulerx.test.helloworld
ContentstringNo

The script content. This parameter is required when you set JobType to python, shell, go, or k8s.

echo 'hello'
ParametersstringNo

The user-defined parameters that you can obtain when the job is running.

test
MaxConcurrencyintegerNo

The maximum number of concurrent instances. By default, only one instance can run at a time. When an instance is running, the next instance is not triggered even if the scheduled start time arrives.

1
MaxAttemptintegerNo

The maximum number of retry attempts in case of a job failure. Specify this parameter based on your business requirements. Default value: 0.

0
AttemptIntervalintegerNo

The time interval between retry attempts in case of a job failure. Unit: seconds. Default value: 30.

30
PageSizeintegerNo

The number of entries per page. You can specify this parameter for MapReduce jobs. Default value: 100.

100
ConsumerSizeintegerNo

The number of threads that a single worker triggers simultaneously. You can specify this parameter for MapReduce jobs. Default value: 5.

5
QueueSizeintegerNo

The maximum capacity of the task queue. You can specify this parameter for MapReduce jobs. Default value: 10000.

10000
DispatcherSizeintegerNo

The number of task distribution threads. This parameter is an advanced configuration item of the MapReduce job. Default value: 5.

5
TimeTypeintegerYes

The time type. Valid values:

  • 1: cron
  • 3: fixed_rate
  • 4: second_delay
  • 5: one_time
  • 100: api
1
TimeExpressionstringNo

The time expression. Specify the time expression based on the value of TimeType:

  • If you set TimeType to 1 (cron), specify this parameter to a standard CRON expression.
  • If you set TimeType to 100 (api), no time expression is required.
  • If you set TimeType to 3 (fixed_rate), specify this parameter to a fixed frequency in seconds. For example, if you set this parameter to 30, the system triggers a job every 30 seconds.
  • If you set TimeType to 4 (second_delay), specify this parameter to a fixed delay after which the job is triggered. Valid values: 1 to 60. Unit: seconds.
  • If you set TimeType to 5 (one_time), specify this parameter to a specific time point at which the job is triggered. The time is in the format of yyyy-MM-dd HH:mm:ss, such as 2022-10-10 10:10:00, or a timestamp in milliseconds.
0 0/10 * * * ?
CalendarstringNo

If you set TimeType to 1 (cron), you can specify calendar days.

This parameter is not supported. You do not need to specify this parameter.
DataOffsetintegerNo

If you set TimeType to 1 (cron), you can specify a time offset. Unit: seconds.

2400
TimezonestringNo

Time zone.

GMT+8
TimeoutEnablebooleanNo

Specifies whether to enable the timeout alert feature. If the feature is enabled, an alert will be triggered upon a timeout. Valid values:

  • true: enables the timeout alert feature.
  • false: disables the timeout alert feature.
false
TimeoutlongNo

The timeout threshold. Unit: seconds. Default value: 7200.

7200
TimeoutKillEnablebooleanNo

Specifies whether to enable the timeout termination feature. If the feature is enabled, a job will automatically be terminated if it times out. Valid values:

  • true: enables the timeout termination feature.
  • false: disables the timeout termination feature.
false
FailEnablebooleanNo

Specifies whether to trigger an alert when a job fails. Valid values:

  • true: triggers an alert when a job fails.
  • false: does not trigger an alert when a job fails.
false
FailTimesintegerNo

The maximum number of consecutive failures before an alert is triggered. An alert will be triggered if the number of consecutive failures reaches the value of this parameter.

2
MissWorkerEnablebooleanNo

Specifies whether to generate an alert if no machines are available to run the job. Valid values:

  • true: generates an alert if no machines are available to run the job.
  • false: does not generate an alert if no machines are available to run the job.
false
SuccessNoticeEnablebooleanNo

Specifies whether to send notifications for successfully running the job.

false
SendChannelstringNo

The method that is used to send alerts. Set the value to sms. Default value: sms.

sms
TaskMaxAttemptintegerNo

The maximum number of retry attempts in case of a job failure. This parameter is an advanced configuration item of the MapReduce job. Default value: 0.

0
TaskAttemptIntervalintegerNo

The time interval between retry attempts in case of a job failure. This parameter is an advanced configuration item of the MapReduce job. Default value: 0.

0
ContactInfoarray<object>No

The information about the alert contact.

objectNo

The information about the array object.

UserPhonestringNo

The mobile number of the alert contact.

1381111****
UserNamestringNo

The name of the alert contact.

Tom
UserMailstringNo

The email address of the alert contact.

test***@***.com
DingstringNo

The webhook URL of the DingTalk chatbot.

https://oapi.dingtalk.com/robot/send?access_token=**********
StatusintegerNo

Specifies whether to enable the job. If this parameter is set to 0, the job is disabled. If this parameter is set to 1, the job is enabled. Default value: 1.

1
XAttrsstringNo

The extended attributes. If you set JobType to k8s, this parameter is required. For a job whose resource type is Job-YAML, set this parameter to {"resource":"job"}. For a job whose resource type is Shell-Script, set this parameter to {"image":"busybox","resource":"shell"}.

{"resource":"job"}

Response parameters

ParameterTypeDescriptionExample
object
Codeinteger

The HTTP status code.

200
Messagestring

The additional information returned.

message
RequestIdstring

The request ID.

39090022-1F3B-4797-8518-6B61095F1AF0
Successboolean

If you set JobType to k8s, this parameter is required. Valid values:

  • true
  • false
true
Dataobject

The details of the job.

JobIdlong

The job ID.

92583

Examples

Sample success responses

JSONformat

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

Error codes

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2024-10-21The response structure of the API has changedView Change Details
2023-03-30The internal configuration of the API is changed, but the call is not affectedView Change Details
2022-12-26The internal configuration of the API is changed, but the call is not affectedView Change Details
2022-09-29The internal configuration of the API is changed, but the call is not affectedView Change Details
2022-09-27The request parameters of the API has changedView Change Details
2022-06-13The request parameters of the API has changedView Change Details

Create a Java job

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 {
     // The region ID. Enter a value by referring to the Endpoints topic or based on the region in which you purchased the service. 
        String regionId = "cn-shanghai";
        // The AccessKey ID used for authentication. You can obtain the AccessKey ID in the Resource Access Management (RAM) console. 
        String accessKeyId = "<yourAccessKeyId>";
        // The AccessKey secret used for authentication. You can obtain the AccessKey secret in the RAM console.
        String accessKeySecret = "<yourAccessKeySecret>";
        // The service name. 
        String productName ="schedulerx2";
        // Refer to the Endpoints topic and enter a domain. 
        String domain ="schedulerx.cn-shanghai.aliyuncs.com";
        // Build an API client. 
        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());
        }
    }

}

Create an HTTP job

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 {
     // The region ID. Enter a value by referring to the Endpoints topic or based on the region in which you purchased the service. 
        String regionId = "cn-shanghai";
        // The AccessKey ID used for authentication. You can obtain the AccessKey ID in the RAM console. 
        String accessKeyId = "<yourAccessKeyId>";
        // The AccessKey secret used for authentication. You can obtain the AccessKey secret in the RAM console. 
        String accessKeySecret = "<yourAccessKeySecret>";
        // The service name. 
        String productName ="schedulerx2";
        // Refer to the Endpoints topic and enter a domain. 
        String domain ="schedulerx.cn-shanghai.aliyuncs.com";
        // Build an API client. 
        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); // Unit: seconds.
        httpAttribute.setRespKey("code");
        httpAttribute.setRespValue("200");
        request.setContent(JsonUtil.toJson(httpAttribute));
        // The POST parameter, in the format of key1=value1&key2=value2. 
        request.setParameters("key1=value1&key2=value2");   
        
        // Send a request. 
        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));
        }
    }
    
}

Create a one-time job

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 {
     // The region ID. Enter a value by referring to the Endpoints topic or based on the region in which you purchased the service. 
        String regionId = "cn-shanghai";
        // The AccessKey ID used for authentication. You can obtain the AccessKey ID in the RAM console.
        String accessKeyId = "xxxxxx";
        // The AccessKey secret used for authentication. You can obtain the AccessKey secret in the RAM console.
        String accessKeySecret = "xxxxxxxx";
        // The service name.
        String productName ="schedulerx2";
        // Refer to the Endpoints topic and enter a domain.
        String domain ="schedulerx.cn-shanghai.aliyuncs.com";
        // Build an API client.
        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");
        // The alert and monitoring feature.
        request.setTimeoutEnable(true);
        request.setTimeoutKillEnable(true);
        request.setFailEnable(true);
        request.setTimeout(12300L);
        // Advanced settings.
        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());
        }
    }
    
}