SchedulerX 2.0 can schedule HTTP jobs and run the jobs in Serverless or Agent mode. You can specify a mode for an HTTP job in the SchedulerX console. This topic describes how to configure an HTTP job in the SchedulerX console.
Overview
The following table describes the differences between and limits of the execution modes of an HTTP job.
Execution mode | Serverless | Agent |
Clients required | No. Requests are initiated by SchedulerX. | Yes. Requests are initiated by the clients that are connected to the jobs. |
Request methods | Only GET and POST are supported. | |
Response parsing | An HTTP response must be in the JSON format. The server checks whether a return key is the same as a specified key to determine whether a request is successful. | |
Job scheduling within seconds | No. Jobs are scheduled only within minutes. | Yes. Jobs are scheduled within seconds. |
Private URL | No. In Serverless mode, Internet access is required to send a request to a specified URL. If the URL of an HTTP interface is in the ip:port format, you must enable Internet access for your machine. | Yes. Private URLs are supported. |
Job name parsing | If a job name is specified in Chinese, the backend can decode the name by using |
Create an HTTP job
To create an HTTP job, you can use the GET or POST request method.
GET
Before you use the GET method to create an HTTP job in the SchedulerX console, add configurations to your client.
Step 1: Configure the parameters in the Basic configuration step
Add the configurations of the GET method to the client.
The following sample code shows the configurations of the GET method. For more information about how to connect a client to SchedulerX, see Connect a Spring Boot application to SchedulerX.
@GET @Path("hi") @Produces(MediaType.APPLICATION_JSON) public RestResult hi(@QueryParam("user") String user) { TestVo vo = new TestVo(); vo.setName(user); RestResult result = new RestResult(); result.setCode(200); result.setData(vo); return result; }
Log on to the SchedulerX console and configure the parameters in the Basic configuration step.
The following figure shows the parameters in this step for creating the HTTP job by using the GET method. For more information about how to create a job in the SchedulerX console, see Create a job.
The following table shows the parameters of the serverless HTTP job.
Parameter
Description
Task name
Specify a name for the job that you want to create.
Description
Specify a description for the job. To facilitate subsequent queries, we recommend that you use simple words.
Application ID
Select the ID of the application that you want to use.
Task type
Select the programming language that you want to use to create the job. Valid values: java, shell, python, go, http, xxljob, and dataworks. If you select shell, python, or go from the drop-down list, a code editor is displayed for you to write a script. In this example, select http.
Full url
Specify a complete URL that starts with
http://
.Request method
In this example, select GET.
Response analysis mode
Select the mode in which the response is parsed. Valid values:
HTTP response code
In this mode, HTTP response codes are returned. If you select this mode, configure standard HTTP response codes.
Custom JSON
If you select this mode, configure the Return check key and Return check value parameters.
By default, an HTTP response that is returned from the server is in the JSON format. The server checks whether the return key and the return value are the same as the specified key and value to determine whether the request is successful.
{ "code": 200, "data": "true", "message": "", "requestId": "446655068791923614103381232971", "success": true }
In the preceding sample code, the server checks whether the value of the success key is true or whether the value of the code key is 200 to determine whether the request is successful.
Custom string
If you select this mode, the server checks whether the return string is the same as the specified string to determine whether the request is successful.
Return check key
Specify the return key that is used to check whether a request is successful. The server uses the key to check only a JSON response.
Return check value
Specify the return value that is used to check whether a request is successful. The server uses the value to check only a JSON response.
Execution timeout
The maximum timeout period is 30 seconds for Basic Edition and 120 seconds for Professional Edition. If the system fails to run the job within the specified timeout period, an error is reported.
cookie
Specify key-value pairs, such as
key1=val1;key2=val2
. Separate multiple key-value pairs with semicolons (;). The maximum length is 300 bytes.After you create the job, find the job on the Task Management page and click Run once in the Operation column.
If the following result appears, the execution of the job is successful.
Step 2: Configure the parameters in the Timing configuration step
In the Timing configuration step of the Create task wizard, configure timing parameters and advanced parameters and click Next Step.
The following table describes the parameters for task scheduling.
Parameter
Description
Time type
none: In most cases, the job is triggered by using a workflow.
cron: The job is scheduled based on a CRON expression.
api: The job is triggered by using an API operation.
fixed_rate: The job is scheduled at a specified interval.
second_delay: The job is scheduled with a second-granularity delay.
onetime: The job is scheduled only once at a specified point in time.
cron expression (available only when Time type is set to cron)
Specify a CRON expression that complies with the CRON syntax. You can also click Use the build tool to specify a CRON expression and click Verify cron to check the CRON expression.
Fixed frequency (available only when Time type is set to fixed_rate)
Specify a fixed interval at which the job is scheduled. Unit: seconds. The value must be greater than 60. For example, a value of 200 specifies that the job is scheduled at an interval of 200 seconds.
Fixed delay (available only when Time type is set to second_delay)
Specify a fixed delay. Unit: seconds. Valid values: 1 to 60. For example, a value of 5 specifies that EDAS triggers scheduling for the job with a delay of five seconds.
If you set the Time type parameter to cron, you can configure the parameters in the Advanced Configuration section. The following table describes the parameters.
Parameter
Description
Time offset
Specify the offset between the timestamp when the job data is processed and the timestamp when the job is scheduled. You can obtain the offset value from the context when SchedulerX runs a job.
Time zone
Select the time zone of a country or region or select a GMT time zone based on your business requirements.
Step 3: Configure the parameters in the Notification configuration step
When you create an HTTP job, you can configure alert rules to receive alert notifications when errors occur in the job. The errors include execution timeout and return values that are different from the specified values.
In the Notification configuration step of the Create task wizard, configure alert settings and alert contacts and click Complete.
POST
Before you use the POST method to create an HTTP job in the SchedulerX console, add configurations to your client.
Step 1: Configure the parameters in the Basic configuration step
Add the configurations of the POST method to the client.
The following sample code shows the configurations of the POST method. For more information about how to connect a client to SchedulerX, see Connect a Spring Boot application to SchedulerX.
import com.alibaba.schedulerx.common.constants.CommonConstants; @POST @Path("createUser") @Produces(MediaType.APPLICATION_JSON) public RestResult createUser(@FormParam("userId") String userId, @FormParam("userName") String userName) { TestVo vo = new TestVo(); System.out.println("userId=" + userId + ", userName=" + userName); vo.setName(userName); RestResult result = new RestResult(); result.setCode(200); result.setData(vo); return result; }
Log on to the SchedulerX console and configure the parameters in the Basic configuration step.
The following figure shows the parameters in this step for creating the HTTP job by using the POST method. For more information about how to create a job in the SchedulerX console, see Create a job.
Parameter
Description
Full url
Specify a complete URL that starts with
http://
.Response analysis mode
Select the mode in which the response is parsed. Valid values:
HTTP response code
In this mode, HTTP response codes are returned. If you select this mode, configure standard HTTP response codes.
Custom JSON
If you select this mode, configure the Return check key and Return check value parameters.
By default, an HTTP response that is returned from the server is in the JSON format. The server checks whether the return key and the return value are the same as the specified key and value to determine whether the request is successful.
{ "code": 200, "data": "true", "message": "", "requestId": "446655068791923614103381232971", "success": true }
In the preceding sample code, the server checks whether the value of the success key is true or whether the value of the code key is 200 to determine whether the request is successful.
Custom string
If you select this mode, the server checks whether the return string is the same as the specified string to determine whether the request is successful.
Return check key and Return check value
By default, an HTTP response that is returned from the server is in the JSON format. The server checks whether the return key and the return value are the same as the specified key and value to determine whether the request is successful.
{ "code": 200, "data": "true", "message": "", "requestId": "446655068791923614103381232971", "success": true }
In the preceding sample code, the server checks whether the value of the success key is true or whether the value of the code key is 200 to determine whether the request is successful.
Execution timeout
The execution timeout period. The maximum value is 30. Unit: seconds. If the system fails to complete the job within the timeout period, an error is returned.
Parameter
The parameters that you want to send by using the POST method. The parameters must be in the format of key1=val1;key2=val2.
Step 2: Configure the parameters in the Timing configuration step
In the Timing configuration step of the Create task wizard, configure timing parameters and advanced parameters and click Next Step.
The following table describes the parameters for task scheduling.
Parameter | Description |
Time type |
|
cron expression (available only when Time type is set to cron) | Specify a CRON expression that complies with the CRON syntax. You can also click Use the build tool to specify a CRON expression and click Verify cron to check the CRON expression. |
Fixed frequency (available only when Time type is set to fixed_rate) | Specify a fixed interval at which the job is scheduled. Unit: seconds. The value must be greater than 60. For example, a value of 200 specifies that the job is scheduled at an interval of 200 seconds. |
Fixed delay (available only when Time type is set to second_delay) | Specify a fixed delay. Unit: seconds. Valid values: 1 to 60. For example, a value of 5 specifies that EDAS triggers scheduling for the job with a delay of five seconds. |
If you set the Time type parameter to cron, you can configure the parameters in the Advanced Configuration section. The following table describes the parameters.
Parameter | Description |
Time offset | Specify the offset between the timestamp when the job data is processed and the timestamp when the job is scheduled. You can obtain the offset value from the context when SchedulerX runs a job. |
Time zone | Select the time zone of a country or region or select a GMT time zone based on your business requirements. |
Step 3: Configure the parameters in the Notification configuration step
When you create an HTTP job, you can configure alert rules to receive alert notifications when errors occur in the job. The errors include execution timeout and return values that are different from the specified values.
In the Notification configuration step of the Create task wizard, configure alert settings and alert contacts and click Complete.
Query the basic information about an HTTP job
The basic information about an HTTP job is contained in the header. If you want to obtain the basic information, you must add the following dependency to the pom.xml file of your client:
<dependency>
<groupId>com.aliyun.schedulerx</groupId>
<artifactId>schedulerx2-common</artifactId>
<version>1.6.0</version>
</dependency>
The following sample code provides an example on how to query the basic information about an HTTP job by using the GET method:
import com.alibaba.schedulerx.common.constants.CommonConstants;
@GET
@Path("hi")
@Produces(MediaType.APPLICATION_JSON)
public RestResult hi(@QueryParam("user") String user,
@HeaderParam(CommonConstants.JOB_ID_HEADER) String jobId,
@HeaderParam(CommonConstants.JOB_NAME_HEADER) String jobName) {
TestVo vo = new TestVo();
vo.setName("armon");
// If the job name is in Chinese, use URLDecode to decode the name.
String decodedJobName = URLDecoder.decode(jobName, "utf-8");
System.out.println("user=" + user + ", jobId=" + jobId + ", jobName=" + decodedJobName);
RestResult result = new RestResult();
result.setCode(200);
result.setData(vo);
return result;
}
The following table describes the basic information.
Constant | key | Value |
JOB_ID_HEADER | schedulerx-jobId | The task ID. |
JOB_NAME_HEADER | schedulerx-jobName | The job name. The name must be in English. |
SCHEDULE_TIMESTAMP_HEADER | schedulerx-scheduleTimestamp | The timestamp when the job was scheduled. |
DATA_TIMESTAMP_HEADER | schedulerx-dataTimestamp | The timestamp when the job data was processed. |
GROUP_ID_HEADER | schedulerx-groupId | The application ID. |
USER_HEADER | schedulerx-user | The username. |
MAX_ATTEMPT_HEADER | schedulerx-maxAttempt | The maximum number of retries for the instance. |
ATTEMPT_HEADER | schedulerx-attempt | The current number of retries for the instance. |
JOB_PARAMETERS_HEADER | schedulerx-jobParameters | The parameters of the job. |
INSTANCE_PARAMETERS_HEADER | schedulerx-instanceParameters | The parameters of the job instance, which are triggered by API operations. |
Check the execution result of an HTTP job
On the Execution List page in the SchedulerX console, view the execution result of an HTTP job. For more information about the example of a successful execution result, see the GET section of this topic.
If the execution of a job fails, click Details in the Operation column of the job to view the cause.
The returned value is different from the expected value.
The execution is timed out.