CREATE TABLE xxl_job_info
(
id serial NOT NULL,
job_group integer NOT NULL,
job_desc varchar(255) NOT NULL,
add_time timestamp with time zone DEFAULT NULL,
update_time timestamp with time zone DEFAULT NULL,
author varchar(64) DEFAULT NULL ,
alarm_email varchar(255) DEFAULT NULL ,
schedule_type varchar(50) NOT NULL DEFAULT 'NONE',
schedule_conf varchar(128) DEFAULT NULL,
misfire_strategy varchar(50) NOT NULL DEFAULT 'DO_NOTHING'
executor_route_strategy varchar(50) DEFAULT NULL ,
executor_handler varchar(255) DEFAULT NULL ,
executor_param varchar(512) DEFAULT NULL ,
executor_block_strategy varchar(50) DEFAULT NULL ,
executor_timeout integer NOT NULL DEFAULT '0' ,
executor_fail_retry_count integer NOT NULL DEFAULT '0' ,
glue_type varchar(50) NOT NULL ,
glue_source text ,
glue_remark varchar(128) DEFAULT NULL ,
glue_updatetime timestamp with time zone DEFAULT NULL ,
child_jobid varchar(255) DEFAULT NULL ,
trigger_status int NOT NULL DEFAULT '0' ,
trigger_last_time bigint NOT NULL DEFAULT '0' ,
trigger_next_time bigint NOT NULL DEFAULT '0' ,
PRIMARY KEY ( id )
);
comment on table xxl_job_info is '任务信息表';
comment on column xxl_job_info.id is '主键';
comment on column xxl_job_info.job_group is '执行器主键ID';
comment on column xxl_job_info.job_desc is '任务描述';
comment on column xxl_job_info.add_time is '任务创建时间';
comment on column xxl_job_info.update_time is '任务更新时间';
comment on column xxl_job_info.author is '作者';
comment on column xxl_job_info.alarm_email is '报警邮件';
comment on column xxl_job_info.schedule_type is '调度类型';
comment on column xxl_job_info.schedule_conf is '调度配置,值含义取决于调度类型';
comment on column xxl_job_info.misfire_strategy is '调度过期策略';
comment on column xxl_job_info.executor_route_strategy is '执行器路由策略';
comment on column xxl_job_info.executor_handler is '执行器任务handler';
comment on column xxl_job_info.executor_param is '执行器任务参数';
comment on column xxl_job_info.executor_block_strategy is '阻塞处理策略';
comment on column xxl_job_info.executor_timeout is '任务执行超时时间,单位秒';
comment on column xxl_job_info.executor_fail_retry_count is '失败重试次数';
comment on column xxl_job_info.glue_type is 'GLUE类型';
comment on column xxl_job_info.glue_source is 'GLUE源代码';
comment on column xxl_job_info.glue_remark is 'GLUE备注';
comment on column xxl_job_info.glue_updatetime is 'GLUE更新时间';
comment on column xxl_job_info.child_jobid is '子任务ID,多个逗号分隔';
comment on column xxl_job_info.trigger_status is '调度状态:0-停止,1-运行';
comment on column xxl_job_info.trigger_last_time is '上次调度时间';
comment on column xxl_job_info.trigger_next_time is '下次调度时间';
CREATE TABLE xxl_job_log (
id serial NOT NULL ,
job_group int NOT NULL ,
job_id int NOT NULL ,
executor_address varchar(255) DEFAULT NULL ,
executor_handler varchar(255) DEFAULT NULL,
executor_param varchar(512) DEFAULT NULL ,
executor_sharding_param varchar(20) DEFAULT NULL ,
executor_fail_retry_count int NOT NULL DEFAULT 0 ,
trigger_time timestamp with time zone DEFAULT NULL,
trigger_code int NOT NULL ,
trigger_msg text ,
handle_time timestamp with time zone DEFAULT NULL ,
handle_code int NOT NULL ,
handle_msg text ,
alarm_status int NOT NULL DEFAULT 0 ,
PRIMARY KEY (id)
);
CREATE INDEX I_trigger_time ON xxl_job_log (trigger_time);
CREATE INDEX I_handle_code ON xxl_job_log (handle_code);
comment on table xxl_job_log is '任务日志表';
comment on column xxl_job_log.id is '主键';
comment on column xxl_job_log.job_group is '执行器主键ID';
comment on column xxl_job_log.job_id is '任务,主键ID';
comment on column xxl_job_log.executor_address is '执行器地址,本次执行的地址';
comment on column xxl_job_log.executor_handler is '执行器任务handler';
comment on column xxl_job_log.executor_param is '执行器任务参数';
comment on column xxl_job_log.executor_sharding_param is '执行器任务分片参数,格式如 1/2';
comment on column xxl_job_log.executor_fail_retry_count is '失败重试次数';
comment on column xxl_job_log.trigger_time is '调度-时间';
comment on column xxl_job_log.trigger_code is '调度-结果';
comment on column xxl_job_log.trigger_msg is '调度-日志';
comment on column xxl_job_log.handle_time is '执行-时间';
comment on column xxl_job_log.handle_code is '执行-状态';
comment on column xxl_job_log.handle_msg is '执行-日志';
comment on column xxl_job_log.alarm_status is '告警状态:0-默认、1-无需告警、2-告警成功、3-告警失败';
create or replace function upd_timestamp() returns trigger as
$$
begin
new.update_time = current_timestamp;
return new;
end
$$
language plpgsql;
CREATE TABLE xxl_job_logglue (
id SERIAL NOT NULL,
job_id int NOT NULL ,
glue_type varchar(50) DEFAULT NULL ,
glue_source text ,
glue_remark varchar(128) NOT NULL ,
add_time timestamp with time zone NULL DEFAULT NULL,
update_time timestamp with time zone NULL DEFAULT NULL,
PRIMARY KEY (id)
);
create trigger t_xxl_job_logglue_update_time before update on xxl_job_logglue for each row execute procedure upd_timestamp();
comment on table xxl_job_logglue is '任务GLUE日志表';
comment on column xxl_job_logglue.id is '主键';
comment on column xxl_job_logglue.job_id is '任务,主键ID';
comment on column xxl_job_logglue.glue_type is 'GLUE类型';
comment on column xxl_job_logglue.glue_source is 'GLUE源代码';
comment on column xxl_job_logglue.glue_remark is 'GLUE备注';
comment on column xxl_job_logglue.add_time is '创建时间';
comment on column xxl_job_logglue.update_time is '修改时间';
CREATE TABLE xxl_job_log_report (
id SERIAL NOT NULL,
trigger_day timestamp with time zone NULL DEFAULT NULL,
running_count int not null default 0,
suc_count int not null default 0,
fail_count int not null default 0,
update_time timestamp with time zone NULL DEFAULT NULL,
PRIMARY KEY (id)
) ;
comment on column xxl_job_log_report.id is '主键';
comment on column xxl_job_log_report.trigger_day is '调度-时间';
comment on column xxl_job_log_report.running_count is '运行中-日志数量';
comment on column xxl_job_log_report.suc_count is '执行成功-日志数量';
comment on column xxl_job_log_report.fail_count is '执行失败-日志数量';
comment on column xxl_job_log_report.update_time is '更新时间';
CREATE TABLE xxl_job_registry (
id SERIAL NOT NULL,
registry_group varchar(255) NOT NULL,
registry_key varchar(255) NOT NULL,
registry_value varchar(255) NOT NULL,
update_time timestamp NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (id)
);
CREATE INDEX i_g_k_v ON xxl_job_registry (registry_group,registry_key,registry_value);
CREATE INDEX i_u ON xxl_job_registry (update_time);
comment on table xxl_job_registry is '任务注册表';
comment on column xxl_job_registry.id is '主键';
comment on column xxl_job_registry.registry_group is '注册分组';
comment on column xxl_job_registry.registry_key is '注册键';
comment on column xxl_job_registry.registry_value is '注册值';
comment on column xxl_job_registry.update_time is '更新时间';
CREATE TABLE xxl_job_group (
id SERIAL NOT NULL,
app_name varchar(64) NOT NULL,
title varchar(12) NOT NULL,
address_type int NOT NULL DEFAULT 0,
address_list varchar(512) DEFAULT NULL,
update_time timestamp DEFAULT NULL,
PRIMARY KEY (id)
);
comment on table xxl_job_group is '任务分组表';
comment on column xxl_job_group.id is '主键';
comment on column xxl_job_group.app_name is '执行器AppName';
comment on column xxl_job_group.title is '执行器名称';
comment on column xxl_job_group.address_type is '执行器地址类型:0=自动注册、1=手动录入';
comment on column xxl_job_group.address_list is '执行器地址列表,多地址逗号分隔';
CREATE TABLE xxl_job_user (
id SERIAL NOT NULL,
username varchar(50) NOT NULL,
password varchar(50) NOT NULL,
role int NOT NULL,
permission varchar(255) DEFAULT NULL,
PRIMARY KEY (id)
);
CREATE UNIQUE INDEX i_username ON xxl_job_user (username);
comment on table xxl_job_user is '任务用户表';
comment on column xxl_job_user.id is '主键';
comment on column xxl_job_user.username is '账号';
comment on column xxl_job_user.password is '密码';
comment on column xxl_job_user.role is '角色:0-普通用户、1-管理员';
comment on column xxl_job_user.permission is '权限:执行器ID列表,多个逗号分割';
CREATE TABLE xxl_job_lock (
lock_name varchar(50) NOT NULL,
PRIMARY KEY (lock_name)
);
comment on table xxl_job_lock is '任务锁表';
comment on column xxl_job_lock.lock_name is '锁名称';
INSERT INTO xxl_job_group ( id , app_name , title , address_type , address_list ) VALUES (1, 'xxl-job-executor-sample', '示例执行器', 0, NULL);
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, '测试任务1', '2018-11-03 22:21:31', '2018-11-03 22:21:31', 'XXL', '', 'CRON', '0 0 0 * * ? *', 'DO_NOTHING', 'FIRST', 'demoJobHandler', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化', '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;
t.id,
t.job_group,
t.job_desc,
t.add_time,
t.update_time,
t.author,
t.alarm_email,
t.schedule_type,
t.schedule_conf,
t.misfire_strategy,
t.executor_route_strategy,
t.executor_handler,
t.executor_param,
t.executor_block_strategy,
t.executor_timeout,
t.executor_fail_retry_count,
t.glue_type,
t.glue_source,
t.glue_remark,
t.glue_updatetime,
t.child_jobid,
t.trigger_status,
t.trigger_last_time,
t.trigger_next_time
SELECT
FROM xxl_job_info AS t
AND t.job_group = #{jobGroup}
AND t.trigger_status = #{triggerStatus}
AND t.job_desc like CONCAt(CONCAt('%', #{jobDesc}), '%')
AND t.executor_handler like CONCAt(CONCAt('%', #{executorHandler}), '%')
AND t.author like CONCAt(CONCAt('%', #{author}), '%')
ORDER BY id DESC
LIMIT #{pagesize} offset #{offset}
SELECT count(1)
FROM xxl_job_info AS t
AND t.job_group = #{jobGroup}
AND t.trigger_status = #{triggerStatus}
AND t.job_desc like CONCAt(CONCAt('%', #{jobDesc}), '%')
AND t.executor_handler like CONCAt(CONCAt('%', #{executorHandler}), '%')
AND t.author like CONCAt(CONCAt('%', #{author}), '%')
INSERT INTO xxl_job_info (
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,
trigger_status,
trigger_last_time,
trigger_next_time
) VALUES (
#{jobGroup},
#{jobDesc},
#{addTime},
#{updateTime},
#{author},
#{alarmEmail},
#{scheduleType},
#{scheduleConf},
#{misfireStrategy},
#{executorRouteStrategy},
#{executorHandler},
#{executorParam},
#{executorBlockStrategy},
#{executorTimeout},
#{executorFailRetryCount},
#{glueType},
#{glueSource},
#{glueRemark},
#{glueUpdatetime},
#{childJobId},
#{triggerStatus},
#{triggerLastTime},
#{triggerNextTime}
);
SELECT
FROM xxl_job_info AS t
WHERe t.id = #{id}
UPDATE xxl_job_info
SET
job_group = #{jobGroup},
job_desc = #{jobDesc},
update_time = #{updateTime},
author = #{author},
alarm_email = #{alarmEmail},
schedule_type = #{scheduleType},
schedule_conf = #{scheduleConf},
misfire_strategy = #{misfireStrategy},
executor_route_strategy = #{executorRouteStrategy},
executor_handler = #{executorHandler},
executor_param = #{executorParam},
executor_block_strategy = #{executorBlockStrategy},
executor_timeout = ${executorTimeout},
executor_fail_retry_count = ${executorFailRetryCount},
glue_type = #{glueType},
glue_source = #{glueSource},
glue_remark = #{glueRemark},
glue_updatetime = #{glueUpdatetime},
child_jobid = #{childJobId},
trigger_status = #{triggerStatus},
trigger_last_time = #{triggerLastTime},
trigger_next_time = #{triggerNextTime}
WHERe id = #{id}
DELETE
FROM xxl_job_info
WHERe id = #{id}
SELECT
FROM xxl_job_info AS t
WHERe t.job_group = #{jobGroup}
SELECT count(1)
FROM xxl_job_info
SELECT
FROM xxl_job_info AS t
WHERe t.trigger_status = 1
and t.trigger_next_time #{maxNextTime}
ORDER BY id ASC
LIMIT #{pagesize}
UPDATE xxl_job_info
SET
trigger_last_time = #{triggerLastTime},
trigger_next_time = #{triggerNextTime},
trigger_status = #{triggerStatus}
WHERe id = #{id}
XxlJobLogGlueMapper.xml
t.id,
t.job_id,
t.glue_type,
t.glue_source,
t.glue_remark,
t.add_time,
t.update_time
INSERT INTO xxl_job_logglue (
job_id,
glue_type,
glue_source,
glue_remark,
add_time,
update_time
) VALUES (
#{jobId},
#{glueType},
#{glueSource},
#{glueRemark},
#{addTime},
#{updateTime}
);
SELECT
FROM xxl_job_logglue AS t
WHERe t.job_id = #{jobId}
ORDER BY id DESC
DELETE FROM xxl_job_logglue
WHERe id NOT in(
SELECt id FROM(
SELECt id FROM xxl_job_logglue
WHERe job_id = #{jobId}
ORDER BY update_time desc
LIMIT #{limit}
) t1
) AND job_id = #{jobId}
DELETE FROM xxl_job_logglue
WHERe job_id = #{jobId}
XxlJobLogMapper.xml
t.id,
t.job_group,
t.job_id,
t.executor_address,
t.executor_handler,
t.executor_param,
t.executor_sharding_param,
t.executor_fail_retry_count,
t.trigger_time,
t.trigger_code,
t.trigger_msg,
t.handle_time,
t.handle_code,
t.handle_msg,
t.alarm_status
SELECT
FROM xxl_job_log AS t
AND t.job_group = #{jobGroup}
AND t.job_id = #{jobId}
AND t.trigger_time = ]]> #{triggerTimeStart}
AND t.trigger_time #{triggerTimeEnd}
AND t.handle_code = 200
AND (
t.trigger_code NOT IN (0, 200) OR
t.handle_code NOT IN (0, 200)
)
AND t.trigger_code = 200
AND t.handle_code = 0
ORDER BY t.trigger_time DESC
LIMIT #{pagesize} offset #{offset}
SELECT count(1)
FROM xxl_job_log AS t
AND t.job_group = #{jobGroup}
AND t.job_id = #{jobId}
AND t.trigger_time = ]]> #{triggerTimeStart}
AND t.trigger_time #{triggerTimeEnd}
AND t.handle_code = 200
AND (
t.trigger_code NOT IN (0, 200) OR
t.handle_code NOT IN (0, 200)
)
AND t.trigger_code = 200
AND t.handle_code = 0
SELECT
FROM xxl_job_log AS t
WHERe t.id = #{id}
INSERT INTO xxl_job_log (
job_group,
job_id,
trigger_time,
trigger_code,
handle_code
) VALUES (
#{jobGroup},
#{jobId},
#{triggerTime},
#{triggerCode},
#{handleCode}
);
UPDATE xxl_job_log
SET
trigger_time= #{triggerTime},
trigger_code= #{triggerCode},
trigger_msg= #{triggerMsg},
executor_address= #{executorAddress},
executor_handler=#{executorHandler},
executor_param= #{executorParam},
executor_sharding_param= #{executorShardingParam},
executor_fail_retry_count= #{executorFailRetryCount}
WHERe id= #{id}
UPDATE xxl_job_log
SET
handle_time= #{handleTime},
handle_code= #{handleCode},
handle_msg= #{handleMsg}
WHERe id= #{id}
delete from xxl_job_log
WHERe job_id = #{jobId}
SELECT
COUNT(handle_code) triggerDayCount,
SUM(CASE WHEN (trigger_code in (0, 200) and handle_code = 0) then 1 else 0 end) as triggerDayCountRunning,
SUM(CASE WHEN handle_code = 200 then 1 else 0 end) as triggerDayCountSuc
FROM xxl_job_log
WHERe trigger_time BETWEEN #{from} and #{to}
SELECT id FROM xxl_job_log
AND job_group = #{jobGroup}
AND job_id = #{jobId}
AND trigger_time #{clearBeforeTime}
AND id NOT in(
SELECt id FROM(
SELECt id FROM xxl_job_log AS t
AND t.job_group = #{jobGroup}
AND t.job_id = #{jobId}
ORDER BY t.trigger_time desc
LIMIT 0, #{clearBeforeNum}
) t1
)
order by id asc
LIMIT #{pagesize}
delete from xxl_job_log
WHERe id in
#{item}
SELECT id FROM xxl_job_log
WHERe not (
(trigger_code in (0, 200) and handle_code = 0)
OR
(handle_code = 200)
)
AND alarm_status = 0
ORDER BY id ASC
LIMIT #{pagesize}
UPDATE xxl_job_log
SET
alarm_status = #{newAlarmStatus}
WHERe id= #{logId} AND alarm_status = #{oldAlarmStatus}
SELECT t.id
FROM xxl_job_log AS t
WHERe t.trigger_code = 200
and t.handle_code = 0
and t.trigger_time #{losedTime}
and t.executor_address not in (
SELECt t2.registry_value
FROM xxl_job_registry AS t2
)
XxlJobLogReportMapper.xml
t.id,
t.trigger_day,
t.running_count,
t.suc_count,
t.fail_count
INSERT INTO xxl_job_log_report (
trigger_day,
running_count,
suc_count,
fail_count
) VALUES (
#{triggerDay},
#{runningCount},
#{sucCount},
#{failCount}
);
UPDATE xxl_job_log_report
SET running_count = #{runningCount},
suc_count = #{sucCount},
fail_count = #{failCount}
WHERe trigger_day = #{triggerDay}
SELECT
FROM xxl_job_log_report AS t
WHERe t.trigger_day between #{triggerDayFrom} and #{triggerDayTo}
ORDER BY t.trigger_day ASC
SELECT
SUM(running_count) running_count,
SUM(suc_count) suc_count,
SUM(fail_count) fail_count
FROM xxl_job_log_report AS t
XxlJobRegistryMapper.xml
t.id,
t.registry_group,
t.registry_key,
t.registry_value,
t.update_time
SELECT t.id
FROM xxl_job_registry AS t
WHERe t.update_time (timestamp'${nowTime}' -INTERVAL '${timeout} S')
DELETE FROM xxl_job_registry
WHERe id in
#{item}
SELECT
FROM xxl_job_registry AS t
WHERe t.update_time ]]> (timestamp'${nowTime}' -INTERVAL '${timeout} S')
UPDATE xxl_job_registry
SET update_time = #{updateTime}
WHERe registry_group = #{registryGroup}
AND registry_key = #{registryKey}
AND registry_value = #{registryValue}
INSERT INTO xxl_job_registry( registry_group , registry_key , registry_value, update_time)
VALUES( #{registryGroup} , #{registryKey} , #{registryValue}, #{updateTime})
DELETE FROM xxl_job_registry
WHERe registry_group = #{registryGroup}
AND registry_key = #{registryKey}
AND registry_value = #{registryValue}
XxlJobUserMapper.xml
t.id,
t.username,
t.password,
t.role,
t.permission
SELECT
FROM xxl_job_user AS t
AND t.username like CONCAt(CONCAt('%', #{username}), '%')
AND t.role = #{role}
ORDER BY username ASC
LIMIT #{pagesize} offset #{offset}
SELECT count(1)
FROM xxl_job_user AS t
AND t.username like CONCAt(CONCAt('%', #{username}), '%')
AND t.role = #{role}
SELECT
FROM xxl_job_user AS t
WHERe t.username = #{username}
INSERT INTO xxl_job_user (
username,
password,
role,
permission
) VALUES (
#{username},
#{password},
#{role},
#{permission}
);
UPDATE xxl_job_user
SET
password = #{password},
role = #{role},
permission = #{permission}
WHERe id = #{id}
DELETE
FROM xxl_job_user
WHERe id = #{id}
评论列表(0条)