数据库

CREATE TABLE `tbl_async_job_desc` (
    `id`              int(11)             NOT NULL auto_increment,
    `name`            varchar(64)         NOT NULL,
    `desc`            varchar(64)         NOT NULL COMMENT '同一个uniqueid只允许一个在运行状态',
    `retry`           int(11) unsigned    NOT NULL DEFAULT 0 COMMENT '',
    `retry_interval`  int(11) unsigned    NOT NULL DEFAULT 0 COMMENT '',
    `timeout`         int(11) unsigned    NOT NULL DEFAULT 0        ,
    `subtasktimeout`  int(11) unsigned    NOT NULL DEFAULT 0  COMMENT '',               
    `parallelism`     int(11) unsigned    NOT NULL DEFAULT 0 COMMENT '',
    `cron`            varchar(64)         NOT NULL DEFAULT '' COMMENT '',
    `cron_count`      int(11) unsigned    NOT NULL DEFAULT 0 COMMENT '定时任务运',
    PRIMARY KEY (`id`),
    UNIQUE KEY (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8mb4
CREATE TABLE `tbl_async_job` (
    `id`           int(11)             NOT NULL auto_increment,
    `parent_task`  int(11)             NOT NULL DEFAULT '0',
    `sub_task`     json                COMMENT 'json array 保存子任务列表',
    `name`         varchar(64)         NOT NULL,
    `groupid`      int(11)             NOT NULL DEFAULT '0',
    `stationid`    int(11)             NOT NULL COMMENT '系统任务默认0',
    `mutex_key`    varchar(32)         NOT NULL COMMENT '同一个mutex_key只允许一个在运行状态',
    `user_data`    varchar(1024)       NOT NULL DEFAULT '',
    `input`        blob,                
    `result`       blob                COMMENT '任务执行结果,如果是子任务则为子任务输出结果',               
    `status`       tinyint(4)          NOT NULL DEFAULT '0' COMMENT '队列中 运行中 暂停 终止 完成',
    `hide`         tinyint(4)          NOT NULL DEFAULT '0' COMMENT '是否隐藏',
    `run_count`    int(11) unsigned    NOT NULL DEFAULT 0 COMMENT '定时任务运行次数',
    `start_time`   datetime            NOT NULL DEFAULT '0000-00-00 00:00:00', 
    `end_time`     datetime            NOT NULL DEFAULT '0000-00-00 00:00:00',
    `progress`     int(11) unsigned    NOT NULL DEFAULT '0',
    `hostname`     varchar(32)         NOT NULL DEFAULT '' COMMENT '运行机器',
    `create_time`  datetime            NOT NULL COMMENT '',
    `modify_time`  datetime            NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
    PRIMARY KEY (`id`),
    KEY `idx_mutex_key` (`mutex_key`),
    KEY `idx_stationid_create` (`stationid`,`create_time`)  COMMENT 'for job/list job/hide'
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4

说明:
sql_mode 需要去掉 NO_ZERO_DATE

说明:
    1. user_task_id 只有order.tasks.batch_create_order 在使用 
        用来判断是否重复提交任务,mongo的ObjectId(),直接改用 task id? 
    2. business_id 目前使用方式:WHERE tbl_async_task.station_id = 'T7442' AND tbl_async_task.business_id = 1 AND tbl_async_task.business_id != 1 AND tbl_async_task.business_id != 8 AND (tbl_async_task.status = 2 OR tbl_async_task.status = 1)
    3. repeat全部为1, 暂时不使用
    4. celery_request_id 全部为空 不再使用
    只统计了最近一个月线上数据