All Products
Search
Document Center

SchedulerX:XXL-JOB jobs

Last Updated:Mar 21, 2024

SchedulerX V2.0 is compatible with XXL-JOB. SchedulerX V2.0 supports the @XxlJob and @JobHandler annotations. You can use SchedulerX V2.0 to schedule XXL-JOB jobs without the need to modify job code.

Background information

XXL-JOB is an out-of-the-box and lightweight distributed job scheduling system. XXL-JOB is designed for fast development, simple learning, and easy expansion. XXL-JOB is a well-known scheduling system in open source communities. Multiple enterprises use XXL-JOB in production environments. Open source XXL-JOB is licensed under General Public License (GPL). Therefore, cloud service providers cannot manage XXL-JOB jobs on their platforms for enterprises and charge service fees. Enterprises must create self-managed jobs. This increases the costs of training, servers, and manpower. SchedulerX V2.0 is a job scheduling platform provided by Alibaba Cloud for commercial use. SchedulerX V2.0 is compatible with XXL-JOB. You can use SchedulerX V2.0 to manage XXL-JOB jobs without the need to modify the code of the jobs.

SchedulerX V2.0 provides the following benefits:

  • Maintenance-free and cost-effective

    To create and run self-managed XXL-JOB jobs, you must prepare at least two servers and one database. If you use SchedulerX V2.0 to manage XXL-JOB jobs, you can reduce the server costs and O&M costs.

  • High capacity and precise scheduling

    Open source XXL-JOB uses database locking to prevent data races. This ensures that only one node runs jobs at a point in time but increases the loads of the database. Statistics indicate that the response latency affects user experience when XXL-JOB processes more than 10,000 jobs at a minute granularity. The response latency is even higher when XXL-JOB processes jobs at a second granularity. SchedulerX V2.0 uses a distributed architecture. SchedulerX V2.0 schedules different jobs to different servers and supports lock-free data races. SchedulerX V2.0 supports horizontal scaling and can schedule millions of jobs. SchedulerX V2.0 uses a dedicated architecture to ensure low latency for jobs that must be triggered at a second granularity. SchedulerX V2.0 is suitable for real-time workloads that need to run jobs at a second granularity. SchedulerX V2.0 also supports one-time jobs. You can use SchedulerX V2.0 to run a one-time job at a specific point in time. After SchedulerX V2.0 completes the job, it automatically deletes the job. You can use one-time jobs to send notifications or close orders at a scheduled point in time.

  • Advanced features

    • Workflows: SchedulerX V2.0 allows you to use workflows to orchestrate jobs in a visualized manner.

    • Throttling: SchedulerX V2.0 allows you to use preemptible queues to schedule jobs based on priorities.

    • Resource isolation: SchedulerX V2.0 supports namespace-level and application-level resource isolation and multi-tenant permission management.

  • High availability

    SchedulerX V2.0 uses a high-availability architecture and creates multiple replicas for each job. The high availability of SchedulerX V2.0 is tested by the internal business of Alibaba Group, such as Double 11 events and disaster recovery drills. SchedulerX V2.0 can schedule jobs as expected even if two cluster nodes fail or when a power outage occurs in a data center.

  • Alerting and O&M for commercial use

    SchedulerX V2.0 is compatible with email alerts and basic O&M features that are provided by XXL-JOB. SchedulerX V2.0 also provides alerting and O&M features for commercial use.

    • Alerting: SchedulerX V2.0 can send alert notifications by using DingTalk messages, text messages, or phone calls.

    • O&M: SchedulerX 2.0 allows you to rerun failed jobs, update job outputs, mark jobs as completed, view stacks, and terminate jobs.

Differences between XXL-JOB based on SchedulerX V2.0 and open source XXL-JOB

The following table describes the differences between XXL-JOB based on SchedulerX V2.0 and open source XXL-JOB.

Feature

Open source XXL-JOB

SchedulerX V2.0-based XXL-JOB

Java jobs

对

对

Go jobs

对

对

Script jobs

对

对

HTTP jobs

错

对

Standalone

对

对

Sharding broadcast

对

对

MapReduce

错

对

Routing policies

First, last, round-robin, and random

Round-robin

Time-based scheduling

cron

cron, fixed_rate, fixed_delay, and one_time

Workflows

错

对

O&M operations

Run one-time jobs and terminate jobs

Run one-time jobs, terminate jobs, rerun jobs, refresh historical data, and mark jobs as completed

Log query

Logs are stored on on-premises executors. If executors crash down, logs are lost.

Logs of the last two weeks are stored in Logstores of Simple Log Service provided by Alibaba Cloud and support for query.

Observability

Historical records and dashboard

Historical records, dashboard, operational records, stack view, and tracing analysis

Monitoring and alerting

Email

Email, DingTalk, Lark, WeCom, custom webhook, text message, and phone call

High availability and disaster recovery

Self-responsible for disaster recovery of databases and servers

Support for multi-data center disaster recovery in the same region

User permissions

User isolation and password-based logon

Support for single sign-on (SSO) and fine-grained permission management of main accounts, Resource Access Management (RAM) users, and RAM roles

Graceful shutdown

对

对

End-to-end canary release

错

对

Throttling

错

对

Connect XXL-JOB to SchedulerX V2.0

  1. To use SchedulerX V2.0 to manage XXL-JOB jobs, modify the pom.xml file of your application. Remove the dependencies of com.xuxueli:XXL-JOB-core, add the dependencies of the SchedulerX agent, and then add the com.aliyun:schedulerx2-plugin-xxljob plug-in.

    The XXL-JOB interface is reconstructed in V2.3.x. Therefore, you must select a connection method based on the version of open source XXL-JOB that you use. The following examples show the configurations of a sample application named schedulerx2-spring-boot-starter:

    • For more information about how to use SchedulerX V2.0 to manage jobs in open source XXL-JOB V2.3.x, see Demo.

      schedulerx2.version specifies the latest version of the client, such as <version>1.8.3</version>. For more information, see Release notes of SchedulerX SDK for Java.

      <!-- Annotation xxl-job-core -->
      <!--
      <dependency>
      	<groupId>com.xuxueli</groupId>
      	<artifactId>xxl-job-core</artifactId>
      	<version>${project.parent.version}</version>
      </dependency>
      -->
      <! -- Add the schedulerx dependency -->
      <dependency>
        <groupId>com.aliyun.schedulerx</groupId>
        <artifactId>schedulerx2-spring-boot-starter</artifactId>
        <version>${schedulerx2.version}</version>
      </dependency>
      <! -- Add schedulerx2-plugin-xxljob -->
      <dependency>
      	<groupId>com.aliyun.schedulerx</groupId>
      	<artifactId>schedulerx2-plugin-xxljob</artifactId>
      	<version>2.3.4</version>
      </dependency>
    • For more information about how to use SchedulerX V2.0 to manage jobs in open source XXL-JOB of a version that is earlier than V2.3.x, see Demo.

      schedulerx2.version specifies the latest version of the client, such as <version>1.8.3</version>. For more information, see Release notes of SchedulerX SDK for Java.

      <!-- Annotation xxl-job-core -->
      <!--
      <dependency>
      	<groupId>com.xuxueli</groupId>
      	<artifactId>xxl-job-core</artifactId>
      	<version>${project.parent.version}</version>
      </dependency>
      -->
      <! -- Add the schedulerx dependency -->
      <dependency>
        <groupId>com.aliyun.schedulerx</groupId>
        <artifactId>schedulerx2-spring-boot-starter</artifactId>
        <version>${schedulerx2.version}</version>
      </dependency>
      <! -- Add schedulerx2-plugin-xxljob -->
      <dependency>
      	<groupId>com.aliyun.schedulerx</groupId>
      	<artifactId>schedulerx2-plugin-xxljob</artifactId>
      	<version>2.2.3</version>
      </dependency>
  2. Add the following configurations to the agent.properties file. For more information, see Use the agent to connect an application to SchedulerX (Script or HTTP jobs).

    spring.schedulerx2.endpoint=192.xx.xx.xx
    spring.schedulerx2.namespace=20e90ffc****
    spring.schedulerx2.groupId=679xxx
    spring.schedulerx2.appKey=71BCC0Exxx

Use the @XxlJob annotation to create a job

Refer to the open source XXL-JOB-executor-sample-springboot project and create a job based on the following sample code:

/**     
* Example of simple jobs in Bean mode     
*/ 
   @XxlJob("demoJobHandler")
    public ReturnT<String> demoJobHandler(String param) throws Exception {
        System.out.println("XXL-JOB, " + param);
        return ReturnT.SUCCESS;
    }
  1. Log on to the SchedulerX console.

  2. In the left-side navigation pane, click Task Management.

  3. In the top navigation bar of the page that appears, select a region. Specify a namespace. Then, click Create task. For more information about the parameters, see Create a job.

  4. On the Task Management page, find the job that you created and click Run once in the Operation column.

  5. On the Task Management page, find the job that you want to manage, click the more in the Operation column, and then select Historical records to view the job Task instance records.

Use the @JobHandler annotation to create a job

Sample code:

@JobHandler(value="HelloJobHandler")
@Componentpublic class HelloJobHandler extends IJobHandler {
    @Override
    public ReturnT<String> execute(String param) throws Exception {
        System.out.println("HelloJobHandler: " + param);
        return SUCCESS;
    }
}
  1. Log on to the SchedulerX console.

  2. In the left-side navigation pane, click Task Management.

  3. In the top navigation bar of the page that appears, select a region. Specify a namespace. Then, click Create task. For more information about the parameters, see Create a job.

  4. On the Task Management page, find the job that you created and click Run once in the Operation column.

  5. On the Task Management page, find the job that you want to manage, click the more in the Operation column, and then select Historical records to view the job Task instance records.

Use sharding broadcast to create a job

In the following sample code, the @XxlJob annotation is used:

/**
* Sharding broadcast job
*/
    @XxlJob("shardingJobHandler")
    public ReturnT<String> shardingJobHandler(String param) throws Exception {
        // Sharding parameters
        int shardIndex = XxlJobContext.getXxlJobContext().getShardIndex();
        int shardTotal = XxlJobContext.getXxlJobContext().getShardTotal();
        XxlJobLogger.log("Sharding parameters: Current shard index = {}, Total number of shards = {}", shardIndex, shardTotal);
        System.out.println("Sharding parameters: Current shard index ="+ shardIndex + ", Total number of shards = " + shardTotal);
        // Business logic
        for (int i = 0; i < shardTotal; i++) {
            if (i == shardIndex) {
                System.out.println("Shard " + i + ", Process the matching shards.");
                XxlJobLogger.log("Shard {}, Process the matching shard", i);
            } else {
                XxlJobLogger.log("Shard {}, Ignore", i);
            }
        }
        return ReturnT.SUCCESS;
    }
  1. Log on to the SchedulerX console.

  2. In the left-side navigation pane, click Task Management.

  3. In the top navigation bar of the page that appears, select a region. Specify a namespace. Then, click Create task. For more information about the parameters, see Create a job.

  4. On the Task Management page, find the job that you created and click Run once in the Operation column.

  5. On the Task Management page, find the job that you want to manage, click the more in the Operation column, and then select Historical records to view the job Task instance records.

Migrate multiple XXL-JOB jobs at the same time

  • Export job configurations from XXL-JOB

    1. Download the export tool.

    2. Decompress the package and add configurations to the application.properties file to export job configurations.GG

      The following sample code shows how to configure the export settings:

      ### xxl-job, datasource
      datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
      datasource.username=root
      datasource.password=123456
      datasource.driver-class-name=com.mysql.cj.jdbc.Driver
      
      ### Specify the name of the application for which you want to export job configurations. If you skip this step, the configurations of the jobs in all groups are exported.
      #xxl-job.app-name=xxl-job-executor-sample
    3. Run the ./start.sh command to export job configurations.SS

    4. After the export is complete, obtain the xxljob_*******.json file that contains only the configurations in bean mode from the current directory.

  • Import XXL-JOB jobs to SchedulerX V2.0

    1. Log on to the SchedulerX V2.0 console.

    2. In the left-side navigation pane, click Task Management.

    3. In the upper part of the Task Management page, click Import Task.

    4. Select the configuration file that you want to import and click Import. Then, the configurations of the XXL-JOB jobs are synchronized to SchedulerX.