This is the 29th day of my participation in the August More Text Challenge

xxl-job admin

introduce

Xxl-job is a distributed task scheduling platform, whose core design goal is rapid development, simple learning, lightweight, easy to expand, out of the box.

Add the dependent

<dependency>
    <groupId>com.xuxueli</groupId>
    <artifactId>xxl-job-core</artifactId>
    <version>${latest stable version}</version>
</dependency>
Copy the code

The database

For details about the database initialization script, see source code location /xxl-job/doc/db/tables_xxl_job.sql

#
# XXL-JOB v23.. 0
# Copyright (c) 2015-present, xuxueli.

CREATE database if NOT EXISTS `xxl_job` default character set utf8mb4 collate utf8mb4_unicode_ci;
use `xxl_job`;

SET NAMES utf8mb4;

CREATE TABLE `xxl_job_info` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `job_group` int(11) NOT NULL COMMENT 'Primary key ID of actuator',
  `job_desc` varchar(255) NOT NULL,
  `add_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  `author` varchar(64) DEFAULT NULL COMMENT 'the writer',
  `alarm_email` varchar(255) DEFAULT NULL COMMENT 'Alarm email',
  `schedule_type` varchar(50) NOT NULL DEFAULT 'NONE' COMMENT 'Schedule type',
  `schedule_conf` varchar(128) DEFAULT NULL COMMENT 'Scheduling configuration, value meaning depends on scheduling type',
  `misfire_strategy` varchar(50) NOT NULL DEFAULT 'DO_NOTHING' COMMENT 'Schedule Expiration Policy',
  `executor_route_strategy` varchar(50) DEFAULT NULL COMMENT 'Executive Routing Policy',
  `executor_handler` varchar(255) DEFAULT NULL COMMENT 'Executor task Handler',
  `executor_param` varchar(512) DEFAULT NULL COMMENT 'Executor Task Parameters',
  `executor_block_strategy` varchar(50) DEFAULT NULL COMMENT 'Blocking Handling Strategy',
  `executor_timeout` int(11) NOT NULL DEFAULT '0' COMMENT 'Task execution timeout in seconds',
  `executor_fail_retry_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Failed retry times',
  `glue_type` varchar(50) NOT NULL COMMENT 'GLUE type',
  `glue_source` mediumtext COMMENT 'GLUE source code ',
  `glue_remark` varchar(128) DEFAULT NULL COMMENT 'GLUE notes',
  `glue_updatetime` datetime DEFAULT NULL COMMENT 'GLUE update time ',
  `child_jobid` varchar(255) DEFAULT NULL COMMENT 'Subtask ID, separated by multiple commas',
  `trigger_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Scheduling status: 0- Stopped, 1- Running',
  `trigger_last_time` bigint(13) NOT NULL DEFAULT '0' COMMENT 'Last dispatch time',
  `trigger_next_time` bigint(13) NOT NULL DEFAULT '0' COMMENT 'Next dispatch time'.PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `job_group` int(11) NOT NULL COMMENT 'Primary key ID of actuator',
  `job_id` int(11) NOT NULL COMMENT 'Task, primary key ID',
  `executor_address` varchar(255) DEFAULT NULL COMMENT 'Executor address, address of this execution',
  `executor_handler` varchar(255) DEFAULT NULL COMMENT 'Executor task Handler',
  `executor_param` varchar(512) DEFAULT NULL COMMENT 'Executor Task Parameters',
  `executor_sharding_param` varchar(20) DEFAULT NULL COMMENT 'Executor task fragment parameter of the form 1/2',
  `executor_fail_retry_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Failed retry times',
  `trigger_time` datetime DEFAULT NULL COMMENT 'Schedule - Time',
  `trigger_code` int(11) NOT NULL COMMENT 'Schedule - Result',
  `trigger_msg` text COMMENT 'Schedule - Log',
  `handle_time` datetime DEFAULT NULL COMMENT 'Execution-time',
  `handle_code` int(11) NOT NULL COMMENT 'Execution-status',
  `handle_msg` text COMMENT 'Execution-Log',
  `alarm_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Alarm status: 0- Default, 1- No alarm, 2- Alarm succeeded, 3- Alarm failed'.PRIMARY KEY (`id`),
  KEY `I_trigger_time` (`trigger_time`),
  KEY `I_handle_code` (`handle_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_log_report` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `trigger_day` datetime DEFAULT NULL COMMENT 'Schedule - Time',
  `running_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Running - Log Quantity',
  `suc_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Execution succeeded - Number of logs',
  `fail_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Failed execution - Number of logs',
  `update_time` datetime DEFAULT NULL.PRIMARY KEY (`id`),
  UNIQUE KEY `i_trigger_day` (`trigger_day`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_logglue` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `job_id` int(11) NOT NULL COMMENT 'Task, primary key ID',
  `glue_type` varchar(50) DEFAULT NULL COMMENT 'GLUE type',
  `glue_source` mediumtext COMMENT 'GLUE source code ',
  `glue_remark` varchar(128) NOT NULL COMMENT 'GLUE notes',
  `add_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL.PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_registry` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `registry_group` varchar(50) NOT NULL,
  `registry_key` varchar(255) NOT NULL,
  `registry_value` varchar(255) NOT NULL,
  `update_time` datetime DEFAULT NULL.PRIMARY KEY (`id`),
  KEY `i_g_k_v` (`registry_group`,`registry_key`,`registry_value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_group` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `app_name` varchar(64) NOT NULL COMMENT 'Executor AppName',
  `title` varchar(12) NOT NULL COMMENT 'Executor name',
  `address_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Actuator address type: 0= automatic registration, 1= manual entry',
  `address_list` text COMMENT 'List of actuator addresses separated by commas',
  `update_time` datetime DEFAULT NULL.PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL COMMENT 'account',
  `password` varchar(50) NOT NULL COMMENT 'password',
  `role` tinyint(4) NOT NULL COMMENT 'Roles: 0- Common user, 1- Administrator',
  `permission` varchar(255) DEFAULT NULL COMMENT 'Permissions: list of executor ids, separated by multiple commas'.PRIMARY KEY (`id`),
  UNIQUE KEY `i_username` (`username`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_lock` (
  `lock_name` varchar(50) NOT NULL COMMENT 'Lock name'.PRIMARY KEY (`lock_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `xxl_job_group`(`id`, `app_name`, `title`, `address_type`, `address_list`, `update_time`) VALUES (1.'xxl-job-executor-sample'.'Sample executor'.0.NULL.'the 2018-11-03 22:21:31' );
INSERT INTO `xxl_job_info`(`id`, `job_group`, `job_desc`, `add_time`, `update_time`, `author`, `alarm_email`, `schedule_type`, `schedule_conf`, `misfire_strategy`, `executor_route_strategy`, `executor_handler`, `executor_param`, `executor_block_strategy`, `executor_timeout`, `executor_fail_retry_count`, `glue_type`, `glue_source`, `glue_remark`, `glue_updatetime`, `child_jobid`) VALUES (1.1.'Test Task 1'.'the 2018-11-03 22:21:31'.'the 2018-11-03 22:21:31'.'XXL'.' '.'CRON'.'0, 0, 0 * *? * '.'DO_NOTHING'.'FIRST'.'demoJobHandler'.' '.'SERIAL_EXECUTION'.0.0.'BEAN'.' '.'GLUE code initialization '.'the 2018-11-03 22:21:31'.' ');
INSERT INTO `xxl_job_user`(`id`, `username`, `password`, `role`, `permission`) VALUES (1.'admin'.'e10adc3949ba59abbe56e057f20f883e'.1.NULL);
INSERT INTO `xxl_job_lock` ( `lock_name`) VALUES ( 'schedule_lock');

commit;


Copy the code
  • -xxl_job_lock: specifies the task scheduling lock table.
  • -xxl_job_group: maintains task actuator information in the actuator information table.
  • -xxl_job_info: used to save extended information about xxL-job scheduling tasks, such as task group, task name, machine address, actuator, execution input parameter, and alarm email.
  • -xxl_job_log: used to save historical information about xxL-job task scheduling, such as scheduling results, execution results, scheduling input parameters, scheduling machines, and actuators.
  • -xxl_job_log_report: scheduling log report: reports that users store XXL-job task scheduling logs, which are used on the report function page of the scheduling center.
  • -xxl_job_logglue: Task GLUE log: saves the GLUE update history and supports the GLUE version tracing function.
  • -xxl_job_registry: indicates the executor registry, which maintains the online executor and scheduling center machine address information.
  • -xxl_job_user: indicates the system user table.

Scheduling center admin

The configuration file

The JDBC link address must be the same as the address of the scheduling database created in Section 2.1
    spring.datasource.url=JDBC: mysql: / / 127.0.0.1:3306 / xxl_job? useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
    spring.datasource.username=root
    spring.datasource.password=root_pwd
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
### Alarm mailbox
    spring.mail.host=smtp.qq.com
    spring.mail.port=25
    spring.mail.username=[email protected]
    spring.mail.password=xxx
    spring.mail.properties.mail.smtp.auth=true
    spring.mail.properties.mail.smtp.starttls.enable=true
    spring.mail.properties.mail.smtp.starttls.required=true
    spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
### Dispatch center communication TOKEN [optional] : non-space enabled;
    xxl.job.accessToken=
[Mandatory] : The default value is "zh_CN"/ Simplified Chinese, and the optional value is "zh_CN"/ simplified Chinese, "zh_TC"/ traditional Chinese and "en"/ English.
    xxl.job.i18n=zh_CN
## Scheduling thread pool maximum thread configuration [required]
    xxl.job.triggerpool.fast.max=200
    xxl.job.triggerpool.slow.max=100
Number of days to save log table data in the scheduling center [Mandatory] : The expired logs are automatically cleared. The value takes effect when the limit is greater than or equal to 7. Otherwise, for example, -1, the automatic clearing function is disabled.
    xxl.job.logretentiondays=30
Copy the code

Start the service visit http://localhost:8080/xxl-job-admin/ into management background

Execution manager

You can create actuators

The database script inserts a sample executor

Task manager

Created in an administrative task

Creating a new task

Basic configuration: - Executor: an executor bound to a task. When a task is triggered, the registered executor is automatically discovered to implement the automatic task discovery function. On the other hand, it can also facilitate task grouping. Each task must be bound to an executor, which can be set in "Executor Management". - Task Description: Provides task description for task management. - Person in charge: the person in charge of the task; N/A Alarm email: specifies the email address for notification when task scheduling fails. Multiple email addresses can be configured. Use commas (,) to separate multiple email addresses. Trigger configuration: - Scheduling type: None: This type does not proactively trigger scheduling. CRON: this type triggers task scheduling through CRON. Fixed speed: This type triggers task scheduling at a fixed speed. According to fixed interval time, periodic trigger; Fixed delay: This type triggers task scheduling with fixed delay. According to the fixed delay time, the delay time is calculated from the end of the last schedule. When the delay time reaches, the next schedule is triggered. - CRON: indicates the CRON expression that triggers the execution of a task. - Fixed speed: firmware speed interval, in seconds; - Fixed delay: indicates the firmware delay interval, in seconds. Task configuration: - Running mode: BEAN mode: Tasks are maintained on the executor side in JobHandler mode. Need to match tasks in the executor with the "JobHandler" attribute; GLUE pattern (Java) : Tasks are maintained in the dispatch center in source code; The task of this pattern is actually a Java class code inherited from IJobHandler and maintained as "Groovy" source code. It runs in an executor project and can inject other services in the executor using @Resource/@Autowire. GLUE pattern (Shell) : Tasks are maintained in the dispatch center in source code; The task in this mode is actually a "shell" script; The GLUE pattern (Python) : Tasks are maintained in the dispatch center in source code; The task in this mode is actually a "Python" script; GLUE pattern (PHP) : Tasks are maintained in the dispatch center in source code; The task in this mode is actually a "PHP" script; GLUE pattern (NodeJS) : Tasks are maintained in the dispatch center in source code; The task in this mode is actually a "nodejs" script; GLUE pattern (PowerShell) : Tasks are maintained in the dispatch center in source code; The task in this mode is actually a "PowerShell" script; - JobHandler: this parameter takes effect when the running mode is BEAN mode and corresponds to the user-defined value of the annotation @jobHandler of the newly developed JobHandler class. - Execution parameters: parameters required for task execution. Advanced configurations: - Routing policy: When an executor is deployed in a cluster, the system provides rich routing policies, including: - Routing policy: The system provides multiple routing policies. FIRST: fixed choice of the FIRST machine; LAST: Fixed selecting the LAST machine; E.g. < 1 > ROUND the table. RANDOM: a machine that is randomly selected to be online; CONSISTENT_HASH: Each task selects a certain machine based on the HASH algorithm, and all tasks are uniformly HASH on different machines. LEAST_FREQUENTLY_USED (least frequently used) : The least frequently used machine is elected first; LEAST_RECENTLY_USED (most recently unused) : The machine that has not been used for the longest time is elected first; FAILOVER: Heartbeat detection is performed in sequence. The first successful heartbeat detection is selected as the target executor and scheduling is initiated. BUSYOVER (busy transfer) : Idle detection is carried out in sequence. The first successful idle detection machine is selected as the target executor and scheduling is initiated. SHARDING_BROADCAST(Sharding broadcast) : Broadcast triggers all machines in the cluster to perform a task, and the system automatically transmits sharding parameters. Sharding tasks can be developed according to sharding parameters; - Subtask: Each task has a unique task ID(the task ID can be obtained from the task list). When the task is successfully executed, the task corresponding to the subtask ID is proactively scheduled. - Scheduling expiration policy: - Ignore: After the scheduling expires, expired tasks are ignored and the next triggering time is recalculated from the current time. - Execute once immediately: After the scheduling expires, execute once immediately and recalculate the next triggering time from the current time. - Blocking processing policy: processing policy when scheduling is too intensive to process; Single-machine serial (default) : After scheduling requests enter the single-machine executor, scheduling requests enter the FIFO queue and run in serial mode. Discards subsequent scheduling requests: After a scheduling request enters the single-node executor, the request is discarded and marked as a failure if a scheduling task is found running on the executor. Overwriting the previous scheduling: After the scheduling request enters the single-machine executor, the running scheduling task is found, the running scheduling task is terminated, the queue is cleared, and the local scheduling task is executed. - Task timeout duration: you can customize the task timeout duration. The task will be interrupted when the task runs out. - Retry times of failures; You can customize the retry times for task failures. When a task fails, the system automatically retries the task based on the preset retry times.Copy the code