All Products
Search
Document Center

SchedulerX:HTTP jobs

Last Updated:Apr 21, 2025

You can use SchedulerX 2.0 to schedule HTTP jobs and run the jobs in Serverless or Agent mode. You can specify a running mode on the SchedulerX Version page. This topic describes how to configure an HTTP job on the SchedulerX Version page.

Prerequisites

  • Serverless: HTTP jobs are executed by using cloud functions or serverless architectures. This mode is suitable for scenarios that require API calls over the Internet and involve a small number of jobs.

  • Agent: HTTP jobs are executed by using the SchedulerX agent that is install on your device. You must manually deploy the SchedulerX agent before you can use this mode. This mode is suitable for scenarios that require internal service calls and complex processing.

Note

You can set the Execution way parameter to serverless or agent when you create an HTTP job in the console.

Execution modes

The following table describes the differences between and limits of the Serverless and Agent modes.

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 method

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 supported

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 in Chinese, the backend system can decode the name by using URLDecode.decode(jobName, "utf-8").

Create an HTTP job

You can use the GET or POST request method to create an HTTP job.

Step 1: Configure the parameters in the Basic Configuration step

GET

  1. Deploy an accessible HTTP service.

    • If an accessible HTTP service is already deployed, perform Step 2 to create an HTTP job in the Microservices Engine (MSE) console. You must prepare the URL of the HTTP service, the request method (GET or POST), and other configuration information.

    • If no accessible HTTP service is deployed, deploy one by calling Java-based HTTP interface. Sample code:

      @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;
      }
  2. Log on to the MSE console, and create an HTTP job on the SchedulerX Version page.

    The following figure shows the configurations of the HTTP job that uses the GET method. For more information about how to create a scheduling job, see Create a job.

    HTTP Serverles 任务

The following table shows the parameters for a serverless HTTP job and an agent HTTP job.

Note

The parameters for the Serverless and Agent modes in the MSE console are the same.

Parameter

Description

Task name

The custom name of the job.

Description

The job description. To facilitate subsequent queries, we recommend that you use simple words.

Application ID

The ID of the application to which the job belongs. Select a value from the drop-down list.

Task type

The job type. In this example, select Http.

Full url

Enter a complete URL that starts with http or https.

Request method

The request method. Select GET or POST.

Response analysis mode

The mode in which the response is parsed. Valid values:

  • HTTP response code

    If you select this mode, HTTP response code is returned. You must configure standard HTTP response code.

  • Custom JSON

    If you select this mode, you must configure the Return check key and Return check value parameters.

    By default, an HTTP response in the JSON format is returned from the server. The system checks whether the request is successful based on the return check key and value that you specified.

    {
      "code": 200,
      "data": "true",
      "message": "",
      "requestId": "446655068791923614103381232971",
      "success": true
    }

    In the preceding sample code, the system determines that the request is successful if the value of the success key is true or the value of the code key is 200.

  • Custom string

    If you select this mode, the system determines that the request is successful if the return string matches the custom string that you specified.

Return check key

The return key that is used to determine whether a request is successful. Only responses in the JSON format are supported.

Return check value

The return value that is used to determine whether a request is successful. Only responses in the JSON format are supported.

Custom string

The custom string that you specify.

Execution timeout

The execution timeout period.

  • If you set Execution way to serverless, the maximum timeout period is 30s for Basic edition and 120s for the Professional edition.

  • If you set Execution way to agent, no limit is imposed on the timeout period.

ContentType

The data type of the request. Valid values:

  • application/x-www-form-urlencoded

  • application/json

Post parameters

The POST form parameters. Example: key1=val1;key2=val2.

cookie

The key-value pairs. Example: key1=val1;key2=val2. Separate multiple key-value pairs with semicolons (;). The maximum length of the value is 300 bytes.

Execution way

  • serverless: The server initiates requests. A URL that can be accessed over the Internet is required.

  • agent: The agent initiates requests. You must install a SchedulerX agent of V1.8.2 or later to initiate requests. You can configure an internal URL.

Advanced Configuration

Task failure retry count

The number of retries after the job failed to run. Default value: 0.

Task failure retry interval

The retry interval between failed jobs. Default value: 30. Unit: seconds.

Task concurrency

The maximum number of instances allowed to run concurrently for the same job. The value 1 indicates that only one job instance is allowed at a time. If the number of instances that concurrently run for a scheduling job exceeds the specified value, the scheduling job is skipped.

Cleaning strategy

The strategy used to clear historical records that are generated during job execution. Default value: Keep last N entries. N is specified by the value of the Retained Number parameter. Valid values:

  • Keep last N entries

  • Keep last N entries by status

Retained Number

The number of historical records to be retained after job execution. Default value: 300.

Step 2: Configure the parameters in the Timing configuration step

  1. In the Timing configuration step of the Create task wizard, configure timing-related parameters and advanced parameters. Then, click Next Step.

    image

    The following table describes the timing-related parameters.

    Parameter

    Description

    Time type

    • none: No scheduling method is used. In most cases, the scheduling job is triggered by a workflow.

    • cron: The job is scheduled based on a CRON expression.

    • api: The scheduling job is triggered by calling an API operation.

    • fixed_rate: The job is scheduled at a fixed interval.

    • second_delay: The job is scheduled with a fixed delay of a few seconds.

    • one_time: The job is scheduled only once at a specified time.

    cron expression

    Enter 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 verify the CRON expression. This parameter is available only if you set the Time type parameter to cron.

    Fixed frequency

    Enter a fixed interval at which the job is scheduled. Unit: seconds. The value must be greater than 60. For example, if you set the value to 200, the job is scheduled at an interval of 200s. This parameter is available only if you set the Time type parameter to fixed_rate.

    Fixed delay

    Enter a fixed delay. Valid values: 1 to 60. Unit: seconds. For example, if you set the value to 5, the scheduling job is triggered with a delay of 5s. This parameter is available only if you set the Time type parameter to second_delay.

    Scheduling time

    Select a date and time. For example, if you set the value to 2025-4-2 12:00:00, the job is scheduled at the time and date that you specified. This parameter is available only if you set the Time type parameter to one_time.

    Advanced Configuration

    Time offset

    Specify the offset between the time when the job data is generated and the time 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 Coordinated Universal Time (UTC) time zone based on your business requirements.

    Calendar

    Specify the effective calendar of the scheduling job. Valid values:

    • Daily scheduling

    • Specify calendar (If you select this option, you must select Financial day or Workday from the drop-down list.)

    Effective time

    Specify the effective time of the scheduling job. Valid values:

    • Effective immediately

    • Start Time (If you select this option, you must select a start date and time.)

Step 3: Configure the parameters in the Notification configuration step

You can configure alert rules when you create the HTTP job. After you create an alert rule, you can receive notifications when a timeout error occurs or when the return values are different from the specified values.

  1. In the Notification configuration step of the Create task wizard, configure the alert-related parameters and alert contacts, and click Complete.

    创建任务-报警配置

  2. After you create the job, find the job on the Tasks page and click Run once in the Operation column of the job.

POST

  1. Deploy an accessible HTTP service.

    • If an accessible HTTP service is already deployed, perform Step 2 to create an HTTP job in the MSE console. You must prepare the URL of the HTTP service, the request method (GET or POST), and other configuration information.

    • If no accessible HTTP service is deployed, deploy one by calling Java-based HTTP interface. Sample code:

      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;
      }
  2. Log on to the MSE console, and create an HTTP job on the SchedulerX Version page.

    The following figure shows the configurations of the HTTP job that uses the POST method. For more information about how to create a scheduling job, see Create a job.Serverless HTTP POST

    The following table shows the parameters for a serverless HTTP job and an agent HTTP job.

    Note

    The parameters for the Serverless and Agent modes in the MSE console are the same.

    Parameter

    Description

    Task name

    The custom name of the job.

    Description

    The job description. To facilitate subsequent queries, we recommend that you use simple words.

    Application ID

    The ID of the application to which the job belongs. Select a value from the drop-down list.

    Task type

    The job type. In this example, select Http.

    Full url

    Enter a complete URL that starts with http or https.

    Request method

    The request method. Select GET or POST.

    Response analysis mode

    The mode in which the response is parsed. Valid values:

    • HTTP response code

      If you select this mode, HTTP response code is returned. You must configure standard HTTP response code.

    • Custom JSON

      If you select this mode, you must configure the Return check key and Return check value parameters.

      By default, an HTTP response in the JSON format is returned from the server. The system checks whether the request is successful based on the return check key and value that you specified.

      {
        "code": 200,
        "data": "true",
        "message": "",
        "requestId": "446655068791923614103381232971",
        "success": true
      }

      In the preceding sample code, the system determines that the request is successful if the value of the success key is true or the value of the code key is 200.

    • Custom string

      If you select this mode, the system determines that the request is successful if the return string matches the custom string that you specified.

    When you set the Response analysis mode parameter to HTTP response code:

    HTTP response code

    The HTTP response code. Default value: 200.

    When you set the Response analysis mode parameter to Custom JSON:

    Return check key

    The return key that is used to determine whether a request is successful. Only responses in the JSON format are supported.

    Return check value

    The return value that is used to determine whether a request is successful. Only responses in the JSON format are supported.

    When you set the Response analysis mode parameter to Custom string:

    Custom string

    The custom string that you specify.

    Execution timeout

    The execution timeout period.

    • If you set Execution way to serverless, the maximum timeout period is 30s for Basic edition and 120s for the Professional edition.

    • If you set Execution way to agent, no limit is imposed on the timeout period.

    ContentType

    The data type of the request when you set the Request method parameter to POST. Valid values:

    • application/x-www-form-urlencoded

    • application/json

    Post parameters

    The POST form parameters when you set the Request method parameter to POST.

    • Example when you set the ContentType parameter to application/x-www-form-urlencoded: key1=value&key2=value2

    • Example when you set the ContentType parameter to application/json: {"key1":"val1","key2":"val2"}

    cookie

    The key-value pairs. Example: key1=val1;key2=val2. Separate multiple key-value pairs with semicolons (;). The maximum length of the value is 300 bytes.

    Execution way

    • serverless: The server initiates requests. A URL that can be accessed over the Internet is required.

    • agent: The agent initiates requests. You must install a SchedulerX agent of V1.8.2 or later to initiate requests. You can configure an internal URL.

    Advanced Configuration

    Task failure retry count

    The number of retries after the job failed to run. Default value: 0.

    Task failure retry interval

    The retry interval between failed jobs. Default value: 30. Unit: seconds.

    Task concurrency

    The maximum number of instances allowed to run concurrently for the same job. The value 1 indicates that only one job instance is allowed at a time. If the number of instances that concurrently run for a scheduling job exceeds the specified value, the scheduling job is skipped.

    Cleaning strategy

    The strategy used to clear historical records that are generated during job execution. Default value: Keep last N entries. N is specified by the value of the Retained Number parameter. Valid values:

    • Keep last N entries

    • Keep last N entries by status

    Retained Number

    The number of historical records to be retained after job execution. Default value: 300.

Step 2: Configure the parameters in the Timing configuration step

In the Timing configuration step of the Create task wizard, configure timing-related parameters and advanced parameters. Then, click Next Step.

创建任务-定时配置

The following table describes the timing-related parameters.

Parameter

Description

Time type

  • none: No scheduling method is used. In most cases, the scheduling job is triggered by a workflow.

  • cron: The job is scheduled based on a CRON expression.

  • api: The scheduling job is triggered by calling an API operation.

  • fixed_rate: The job is scheduled at a fixed interval.

  • second_delay: The job is scheduled with a fixed delay of a few seconds.

  • one_time: The job is scheduled only once at a specified time.

cron expression

Enter 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 verify the CRON expression. This parameter is available only if you set the Time type parameter to cron.

Fixed frequency

Enter a fixed interval at which the job is scheduled. Unit: seconds. The value must be greater than 60. For example, if you set the value to 200, the job is scheduled at an interval of 200s. This parameter is available only if you set the Time type parameter to fixed_rate.

Fixed delay

Enter a fixed delay. Valid values: 1 to 60. Unit: seconds. For example, if you set the value to 5, the scheduling job is triggered with a delay of 5s. This parameter is available only if you set the Time type parameter to second_delay.

Scheduling time

Select a date and time. For example, if you set the value to 2025-4-2 12:00:00, the job is scheduled at the time and date that you specified. This parameter is available only if you set the Time type parameter to one_time.

Advanced Configuration

Time offset

Specify the offset between the time when the job data is generated and the time 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 Coordinated Universal Time (UTC) time zone based on your business requirements.

Calendar

Specify the effective calendar of the scheduling job. Valid values:

  • Daily scheduling

  • Specify calendar (If you select this option, you must select Financial day or Workday from the drop-down list.)

Effective time

Specify the effective time of the scheduling job. Valid values:

  • Effective immediately

  • Start Time (If you select this option, you must select a start date and time.)

Step 3: Configure the parameters in the Notification configuration step

You can configure alert rules when you create the HTTP job. After you create an alert rule, you can receive notifications when a timeout error occurs or when the return values are different from the specified values.

  1. In the Notification configuration step of the Create task wizard, configure the alert-related parameters and alert contacts, and click Complete.

    创建任务-报警配置

  2. After you create the job, find the job on the Tasks page and click Run once in the Operation column of the job.

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;
}

Job constant description

The following table describes the CommonConstants constants.

CommonConstants constant

key

Value

JOB_ID_HEADER

schedulerx-jobId

The job 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 is scheduled.

DATA_TIMESTAMP_HEADER

schedulerx-dataTimestamp

The timestamp when the job data is 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 number of retries for the instance.

JOB_PARAMETERS_HEADER

schedulerx-jobParameters

The job parameters.

INSTANCE_PARAMETERS_HEADER

schedulerx-instanceParameters

The job instance parameters, which are injected when the job is triggered by calling API operations.

Result verification

On the Instances page of SchedulerX, view the execution result of the HTTP job.

If the job execution fails, click Details in the Operation column of the job to view the failure cause.

  • The returned value is different from the expected value.返回值和期望不相同

  • The execution is timed out.执行超时