HTTP job

Updated at:

SchedulerX HTTP jobs require an agent for scheduling.

Prerequisites

  • serverless mode: Triggers HTTP jobs through cloud functions or a serverless architecture. This mode is suitable for public API calls and lightweight jobs.

  • agent mode: Executes HTTP jobs by installing the SchedulerX agent on the target device. You must deploy the SchedulerX agent in advance. This mode is suitable for internal service calls and complex processing scenarios.

Note

When creating an HTTP job in the MSE console, you can select either serverless or agent for the execution mode parameter.

Execution modes

The following table compares SchedulerX HTTP jobs and MSE-XXLJOB HTTP jobs:

SchedulerX Serverless (Deprecated)

SchedulerX agent

MSE-XXL-JOB

Client integration required

No. Requests are initiated by the server.

Yes. The server sends a command to the client, which initiates the request.

No. Requests are initiated by the server.

Request method

Currently, only GET and POST are supported. Support for other methods will be added based on user demand.

Request definition

Supports only cookie settings and POST parameter settings.

Supports all HTTP request parameter settings, including Header, Query, and Body.

Response definition

  • HTTP response code: Determines job success based on the HTTP response code.

  • JSON response body parsing: The API response must be in JSON format. Determines job success by evaluating a key-value pair.

  • String response body: The API response is treated as a string. Determines job success by performing an exact match on the response body.

Second-level scheduling

No, only minute-level scheduling is supported.

Yes

Yes

Internal URL support

No

Yes

Execution without a domain name

No

Yes, supports integration with Kubernetes Services without requiring a gateway or domain name.

Broadcast sharding support

No

Yes

Task name parsing

If the task name contains Chinese characters, the backend can decode it by using URLDecode.decode(jobName, "utf-8").

How to create an HTTP job

You can create an HTTP job by using either the GET or POST request method.

Step 1: Configure basic information

GET

  1. Deploy an accessible HTTP service.

    • If you have an accessible HTTP service, proceed to Step 2 to create the HTTP job in the MSE console. Have the URL, request method (such as GET or POST), and other configuration details for the target HTTP service ready.

    • If you have not deployed an HTTP service, refer to the following sample Java code for developing an HTTP endpoint:

      @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. Create an HTTP job in the MSE console.

    Configure the parameters for the GET method as follows. For more information about how to create a scheduled job, see Create a scheduled job. Set task name to http_get, select HTTP for task type, enter the target request URL in the full URL field, select GET for request method, and select Custom JSON for response parsing mode. Set return check key to code and return check value to 200. Set execution timeout to 10 seconds and select serverless for execution mode.

POST

  1. Deploy an accessible HTTP service.

    • If you have an accessible HTTP service, proceed to Step 2 to create the HTTP job in the MSE console. Have the URL, request method (such as GET or POST), and other configuration details for the target HTTP service ready.

    • If you have not deployed an HTTP service, refer to the following sample Java code for developing an HTTP endpoint:

      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. Create an HTTP job in the MSE console.

    Configure the parameters for the POST method as follows. For more information about how to create a scheduled job, see Create a scheduled job. Set task name to http_post, select HTTP for task type, enter the target request URL in the full URL field, and select POST for request method. Select Custom JSON for response parsing mode, set return check key to code, and set return check value to 200. Set execution timeout to 10 seconds. Select application/x-www-form-urlencoded for ContentType, enter the parameters in the format key1=value1&key2=value2 in the POST parameters field, and select serverless for execution mode.

The following table describes the parameters for serverless HTTP and agent HTTP jobs.

Note

The configuration parameters for the serverless and agent execution modes are the same in the MSE console.

Parameter

Description

task name

A custom name for the job.

Description

A brief description of the job for easier identification and searching.

application ID

The application to which the job belongs. You can select an application from the drop-down list.

task type

The type of processor for the job. In this scenario, select HTTP.

full URL

Enter the full URL, which must start with http or https.

request method

Select a request method. Valid values: GET and POST.

response parsing mode

Select a response parsing mode. The following modes are supported:

  • HTTP response code

    Determines success based on the HTTP response code. You must specify the HTTP response code that signifies success.

  • Custom JSON

    Specify a return check key and a return check value.

    By default, the server expects the HTTP response in JSON format. It verifies the job's success by checking if the value of the specified key matches the expected value.

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

    In the preceding example, you can verify success by checking if the key success has a value of true, or if the key code has a value of 200.

  • Custom string

    Determines job success by performing an exact match on a custom string in the response.

If you select HTTP response code for response parsing mode:

HTTP response code

The HTTP response code that indicates a successful job. The default value is 200.

If you select Custom JSON for response parsing mode:

return check key

The key in the JSON response to check for success. Only JSON return values are supported.

return check value

The value in the JSON response that indicates success. Only JSON return values are supported.

If you select Custom string for response parsing mode:

Custom string

The custom string to match.

execution timeout

  • serverless: The maximum timeout is 30 seconds for the Basic Edition and 120 seconds for the Professional Edition.

  • agent: No limit.

ContentType

If request method is set to POST, specify the data format of the request body. The following data formats are supported:

  • application/x-www-form-urlencoded

  • application/json

POST parameters

If request method is set to POST, specify the POST form parameters. Examples:

  • When ContentType is application/x-www-form-urlencoded: key1=value&key2=value2.

  • When ContentType is application/json: {"key1":"val1","key2":"val2"}.

cookie

For example: key1=val1;key2=val2. Separate multiple values with semicolons (;). The maximum length is 300 bytes.

execution mode

  • serverless: The server initiates the request. A publicly accessible URL is required.

  • agent: Requires the SchedulerX agent to be deployed in advance. The client initiates the request. You can configure an internal URL. This mode is supported only for clients of version 1.8.2 or later. For more information about how to deploy the SchedulerX agent, see Agent access (for scripts or HTTP jobs).

Advanced configuration

task failure retry count

The number of times to retry a job after it fails. The default value is 0.

task failure retry interval

The interval between retries after a job fails. The default value is 30. Unit: seconds.

task concurrency

The maximum number of concurrent instances for a job. A value of 1 means that instances cannot run concurrently. If this limit is exceeded, new instances are skipped.

cleanup policy

The policy for cleaning up job instance history. The default policy is to keep the latest N records, where N is the value of retention count.

  • Keep the latest N records.

  • Keep the latest N records by status.

retention count

The number of job instance history records to retain. The default value is 300.

Step 2: Configure scheduling settings

On the scheduling settings wizard page, set the scheduling and advanced parameters, and then click Next.

The following table describes the scheduling parameters.

Parameter

Description

schedule type

  • none: No scheduling is performed. Jobs are typically triggered by a workflow.

  • cron: The job is scheduled by using a cron expression.

  • api: The job is triggered by an API call.

  • fixed_rate: The job is scheduled to run at a fixed rate.

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

  • onetime: The job runs only once.

cron expression (applies only to the cron schedule type)

Enter a cron expression. You can enter an expression directly or use a tool to generate and validate one.

fixed rate (applies only to the fixed_rate schedule type)

The fixed rate at which the job is scheduled. Unit: seconds. The value must be 60 or greater. For example, a value of 200 means the job is scheduled to run every 200 seconds.

fixed delay (applies only to the second_delay schedule type)

The fixed delay before the job is triggered. Unit: seconds. The value must be in the range of 1 to 60. For example, a value of 5 means the job is triggered after a 5-second delay.

scheduling time (applies only to the one_time schedule type)

Select a date and time. For example, 2025-4-2 12:00:00 schedules the job to run once.

Advanced configuration

data time offset

The offset of the data time relative to the scheduling time. You can retrieve this value from the context at runtime.

time zone

Select a time zone based on your business requirements. You can select from common countries or regions, or use a standard GMT time zone.

calendar

Specifies the calendar for the job schedule.

  • Daily scheduling.

  • Specify calendar. You must specify a financial day or a workday.

Effective Time

The time at which the job becomes active.

  • Effective immediately.

  • Start time. You must select a start date and time.

Step 3: Configure notification settings

HTTP jobs support failure alerts. If an issue such as a timeout or an unexpected return value occurs, you can set alert conditions when you create the job to receive corresponding notifications.

  1. On the notification settings wizard page, set the alert parameters and contacts, and then click Complete.

    Alert parameters include timeout alert (enabled by default; requires setting a timeout in seconds), timeout termination (disabled by default), success notification (disabled by default), failure alert (enabled by default; requires setting the consecutive failure count), and no available agent alert (enabled by default). For Notification Channels and Contacts, you can select Application Group Contacts or Custom.

  2. After the job is created, navigate to the job management page. In the Actions column for the target job, click run once.

    A successful execution is indicated by the following result. After the job runs successfully, you can view the execution result on the job instance history page. Click the target instance. On the details panel that appears, the basic information tab displays fields such as the instance ID, task name, start time, end time, and scheduling time. The result message {"code":200,"data":{"name":"armon"}} indicates a successful job run with the expected JSON data.

Get basic job information

The basic information of an HTTP job is included in the request header. To obtain this information, add the following dependency to your client's pom.xml file.

<dependency>
    <groupId>com.aliyun.schedulerx</groupId>
    <artifactId>schedulerx2-common</artifactId>
    <version>1.6.0</version>
</dependency>

The following GET method example shows how to obtain basic job information.

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 JobName contains Chinese characters, URL decoding is required.
    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 definitions

The following table describes the job-related constants available in CommonConstants.

CommonConstants constant

Key

Description

JOB_ID_HEADER

schedulerx-jobId

Job ID.

JOB_NAME_HEADER

schedulerx-jobName

Job name. If the name contains non-ASCII characters (like Chinese), it is URL-encoded in the header.

SCHEDULE_TIMESTAMP_HEADER

schedulerx-scheduleTimestamp

The timestamp of the scheduling time.

DATA_TIMESTAMP_HEADER

schedulerx-dataTimestamp

The timestamp of the data time.

GROUP_ID_HEADER

schedulerx-groupId

Application ID.

USER_HEADER

schedulerx-user

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 job parameters.

INSTANCE_PARAMETERS_HEADER

schedulerx-instanceParameters

The job instance parameters. An API call is required.

Verify the result

You can view the execution results of HTTP jobs on the execution list page. For successful results, see GET.

When a task fails, click Details to view the specific reason for the failure:

  • The returned value is different from the expected value. On the Basic Information tab of the job instance details, the Result or Error Message section displays the error: The returned value is different from the expected value. The returned JSON contains "success":false, which indicates that the HTTP job failed.

  • Execution timed out. On the Basic Information page of the job instance, the Result or Error Message field shows a specific exception, such as java.net.SocketTimeoutException. This indicates that the HTTP job failed because of a network timeout. The trigger method is manual.