mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: optimize the code of persistence layer entity class
This commit is contained in:
parent
fe03b8faab
commit
2c51e0601d
@ -69,11 +69,9 @@ CREATE TABLE `instance_info`
|
|||||||
`gmt_create` datetime not NULL COMMENT '创建时间',
|
`gmt_create` datetime not NULL COMMENT '创建时间',
|
||||||
`gmt_modified` datetime not NULL COMMENT '更新时间',
|
`gmt_modified` datetime not NULL COMMENT '更新时间',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `idx01_instance_info` (`job_id`),
|
KEY `idx01_instance_info` (`job_id`, 'status'),
|
||||||
KEY `idx02_instance_info` (`app_id`),
|
KEY `idx02_instance_info` (`app_id`, `status`),
|
||||||
KEY `idx03_instance_info` (`instance_id`),
|
KEY `idx03_instance_info` (`instance_id`, `status`)
|
||||||
KEY `idx04_instance_info` (`wf_instance_id`),
|
|
||||||
KEY `idx05_instance_info` (`expected_trigger_time`)
|
|
||||||
) ENGINE = InnoDB
|
) ENGINE = InnoDB
|
||||||
AUTO_INCREMENT = 1
|
AUTO_INCREMENT = 1
|
||||||
DEFAULT CHARSET = utf8mb4
|
DEFAULT CHARSET = utf8mb4
|
||||||
@ -110,15 +108,13 @@ CREATE TABLE `job_info`
|
|||||||
`task_retry_num` int not NULL default 0 COMMENT 'Task重试次数',
|
`task_retry_num` int not NULL default 0 COMMENT 'Task重试次数',
|
||||||
`time_expression` varchar(255) default NULL COMMENT '时间表达式,内容取决于time_expression_type,1:CRON/2:NULL/3:LONG/4:LONG',
|
`time_expression` varchar(255) default NULL COMMENT '时间表达式,内容取决于time_expression_type,1:CRON/2:NULL/3:LONG/4:LONG',
|
||||||
`time_expression_type` int not NULL COMMENT '时间表达式类型,1:CRON/2:API/3:FIX_RATE/4:FIX_DELAY,5:WORKFLOW\n)',
|
`time_expression_type` int not NULL COMMENT '时间表达式类型,1:CRON/2:API/3:FIX_RATE/4:FIX_DELAY,5:WORKFLOW\n)',
|
||||||
`tag` varchar(255) DEFAULT NULL COMMENT 'TAG',
|
`tag` varchar(255) DEFAULT NULL COMMENT 'TAG',
|
||||||
`log_config` varchar(255) DEFAULT NULL COMMENT '日志配置',
|
`log_config` varchar(255) DEFAULT NULL COMMENT '日志配置',
|
||||||
`extra` varchar(255) DEFAULT NULL COMMENT '扩展字段',
|
`extra` varchar(255) DEFAULT NULL COMMENT '扩展字段',
|
||||||
`gmt_create` datetime not NULL COMMENT '创建时间',
|
`gmt_create` datetime not NULL COMMENT '创建时间',
|
||||||
`gmt_modified` datetime not NULL COMMENT '更新时间',
|
`gmt_modified` datetime not NULL COMMENT '更新时间',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `idx01_job_info` (`app_id`),
|
KEY `idx01_job_info` (`app_id`, `status`, `time_expression_type`, `next_trigger_time`)
|
||||||
KEY `idx02_job_info` (`job_name`),
|
|
||||||
KEY `idx03_job_info` (`next_trigger_time`)
|
|
||||||
) ENGINE = InnoDB
|
) ENGINE = InnoDB
|
||||||
AUTO_INCREMENT = 1
|
AUTO_INCREMENT = 1
|
||||||
DEFAULT CHARSET = utf8mb4
|
DEFAULT CHARSET = utf8mb4
|
||||||
@ -154,7 +150,8 @@ CREATE TABLE `server_info`
|
|||||||
`gmt_modified` datetime DEFAULT NULL COMMENT '更新时间',
|
`gmt_modified` datetime DEFAULT NULL COMMENT '更新时间',
|
||||||
`ip` varchar(128) DEFAULT NULL COMMENT '服务器IP地址',
|
`ip` varchar(128) DEFAULT NULL COMMENT '服务器IP地址',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY `uidx01_server_info` (`ip`)
|
UNIQUE KEY `uidx01_server_info` (`ip`),
|
||||||
|
KEY `idx01_server_info` (`gmt_modified`)
|
||||||
) ENGINE = InnoDB
|
) ENGINE = InnoDB
|
||||||
AUTO_INCREMENT = 1
|
AUTO_INCREMENT = 1
|
||||||
DEFAULT CHARSET = utf8mb4
|
DEFAULT CHARSET = utf8mb4
|
||||||
@ -204,7 +201,7 @@ CREATE TABLE `workflow_info`
|
|||||||
`gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
|
`gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
|
||||||
`gmt_modified` datetime DEFAULT NULL COMMENT '更新时间',
|
`gmt_modified` datetime DEFAULT NULL COMMENT '更新时间',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `idx01_workflow_info` (`app_id`)
|
KEY `idx01_workflow_info` (`app_id`, `status`, `time_expression_type`, next_trigger_time)
|
||||||
) ENGINE = InnoDB
|
) ENGINE = InnoDB
|
||||||
AUTO_INCREMENT = 1
|
AUTO_INCREMENT = 1
|
||||||
DEFAULT CHARSET = utf8mb4
|
DEFAULT CHARSET = utf8mb4
|
||||||
@ -231,9 +228,9 @@ CREATE TABLE `workflow_instance_info`
|
|||||||
`gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
|
`gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
|
||||||
`gmt_modified` datetime DEFAULT NULL COMMENT '更新时间',
|
`gmt_modified` datetime DEFAULT NULL COMMENT '更新时间',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
unique index uidx01_wf_instance (wf_instance_id),
|
unique index uidx01_wf_instance (`wf_instance_id`),
|
||||||
index idx01_wf_instance (workflow_id),
|
index idx01_wf_instance (`workflow_id`, `status`),
|
||||||
index idx02_wf_instance (app_id, status)
|
index idx02_wf_instance (`app_id`, `status`, `expected_trigger_time`)
|
||||||
) ENGINE = InnoDB
|
) ENGINE = InnoDB
|
||||||
AUTO_INCREMENT = 1
|
AUTO_INCREMENT = 1
|
||||||
DEFAULT CHARSET = utf8mb4
|
DEFAULT CHARSET = utf8mb4
|
||||||
@ -258,9 +255,7 @@ CREATE TABLE `workflow_node_info`
|
|||||||
`type` int DEFAULT NULL COMMENT '节点类型,1:任务JOB',
|
`type` int DEFAULT NULL COMMENT '节点类型,1:任务JOB',
|
||||||
`workflow_id` bigint DEFAULT NULL COMMENT '工作流ID',
|
`workflow_id` bigint DEFAULT NULL COMMENT '工作流ID',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `idx01_workflow_node_info` (`app_id`),
|
KEY `idx01_workflow_node_info` (`workflow_id`,`gmt_create`)
|
||||||
KEY `idx02_workflow_node_info` (`workflow_id`),
|
|
||||||
KEY `idx03_workflow_node_info` (`job_id`)
|
|
||||||
) ENGINE = InnoDB
|
) ENGINE = InnoDB
|
||||||
AUTO_INCREMENT = 1
|
AUTO_INCREMENT = 1
|
||||||
DEFAULT CHARSET = utf8mb4
|
DEFAULT CHARSET = utf8mb4
|
||||||
|
@ -105,7 +105,7 @@ public class InstanceStatusCheckService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查等待 worker 接收的实例
|
* 检查等待 worker 接收的实例
|
||||||
* WAITING_WORKER_RECEIVE 超时:由于网络错误导致 worker 未接受成功
|
* WAITING_WORKER_RECEIVE 超时:由于网络错误导致 worker 未接受成功
|
||||||
*/
|
*/
|
||||||
public void checkWaitingWorkerReceiveInstance() {
|
public void checkWaitingWorkerReceiveInstance() {
|
||||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||||
@ -240,7 +240,7 @@ public class InstanceStatusCheckService {
|
|||||||
}
|
}
|
||||||
// CRON 和 API一样,失败次数 + 1,根据重试配置进行重试
|
// CRON 和 API一样,失败次数 + 1,根据重试配置进行重试
|
||||||
if (instance.getRunningTimes() < jobInfoOpt.get().getInstanceRetryNum()) {
|
if (instance.getRunningTimes() < jobInfoOpt.get().getInstanceRetryNum()) {
|
||||||
dispatchService.redispatchAsync(instance.getInstanceId(),InstanceStatus.RUNNING.getV());
|
dispatchService.redispatchAsync(instance.getInstanceId(), InstanceStatus.RUNNING.getV());
|
||||||
} else {
|
} else {
|
||||||
final Optional<InstanceInfoDO> opt = instanceInfoRepository.findById(instance.getId());
|
final Optional<InstanceInfoDO> opt = instanceInfoRepository.findById(instance.getId());
|
||||||
opt.ifPresent(e -> updateFailedInstance(e, SystemInstanceResult.REPORT_TIMEOUT));
|
opt.ifPresent(e -> updateFailedInstance(e, SystemInstanceResult.REPORT_TIMEOUT));
|
||||||
|
@ -14,7 +14,7 @@ import java.util.Date;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(uniqueConstraints = {@UniqueConstraint(name = "appNameUK", columnNames = {"appName"})})
|
@Table(uniqueConstraints = {@UniqueConstraint(name = "uidx01_app_info", columnNames = {"appName"})})
|
||||||
public class AppInfoDO {
|
public class AppInfoDO {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -14,7 +14,7 @@ import java.util.Date;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(indexes = {@Index(columnList = "appId")})
|
@Table(indexes = {@Index(name = "idx01_container_info", columnList = "appId")})
|
||||||
public class ContainerInfoDO {
|
public class ContainerInfoDO {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -19,7 +19,11 @@ import java.util.Date;
|
|||||||
@Entity
|
@Entity
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Table(indexes = {@Index(columnList = "jobId"), @Index(columnList = "appId"), @Index(columnList = "instanceId")})
|
@Table(indexes = {
|
||||||
|
@Index(name = "idx01_instance_info", columnList = "jobId,status"),
|
||||||
|
@Index(name = "idx02_instance_info", columnList = "appId,status"),
|
||||||
|
@Index(name = "idx03_instance_info", columnList = "instanceId,status")
|
||||||
|
})
|
||||||
public class InstanceInfoDO {
|
public class InstanceInfoDO {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@ -40,6 +44,7 @@ public class InstanceInfoDO {
|
|||||||
private Long instanceId;
|
private Long instanceId;
|
||||||
/**
|
/**
|
||||||
* 任务参数(静态)
|
* 任务参数(静态)
|
||||||
|
*
|
||||||
* @since 2021/2/01
|
* @since 2021/2/01
|
||||||
*/
|
*/
|
||||||
@Lob
|
@Lob
|
||||||
|
@ -19,7 +19,9 @@ import java.util.Date;
|
|||||||
@Entity
|
@Entity
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Table(indexes = {@Index(columnList = "appId")})
|
@Table(indexes = {
|
||||||
|
@Index(name = "idx01_job_info", columnList = "appId,status,timeExpressionType,nextTriggerTime"),
|
||||||
|
})
|
||||||
public class JobInfoDO {
|
public class JobInfoDO {
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import java.util.Date;
|
|||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Table(uniqueConstraints = {@UniqueConstraint(name = "lockNameUK", columnNames = {"lockName"})})
|
@Table(uniqueConstraints = {@UniqueConstraint(name = "uidx01_oms_lock", columnNames = {"lockName"})})
|
||||||
public class OmsLockDO {
|
public class OmsLockDO {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -16,7 +16,10 @@ import java.util.Date;
|
|||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Table(uniqueConstraints = {@UniqueConstraint(columnNames = "ip")})
|
@Table(
|
||||||
|
uniqueConstraints = {@UniqueConstraint(name = "uidx01_server_info", columnNames = "ip")},
|
||||||
|
indexes = {@Index(name = "idx01_server_info", columnList = "gmtModified")}
|
||||||
|
)
|
||||||
public class ServerInfoDO {
|
public class ServerInfoDO {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -14,7 +14,10 @@ import java.util.Date;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table
|
@Table(indexes = {
|
||||||
|
@Index(name = "uidx01_user_info", columnList = "username"),
|
||||||
|
@Index(name = "uidx02_user_info", columnList = "email")
|
||||||
|
})
|
||||||
public class UserInfoDO {
|
public class UserInfoDO {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -18,7 +18,9 @@ import java.util.Date;
|
|||||||
@Entity
|
@Entity
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Table(indexes = {@Index(columnList = "appId")})
|
@Table(indexes = {
|
||||||
|
@Index(name = "idx01_workflow_info",columnList = "appId,status,timeExpressionType,nextTriggerTime")
|
||||||
|
})
|
||||||
public class WorkflowInfoDO {
|
public class WorkflowInfoDO {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -18,7 +18,13 @@ import java.util.Date;
|
|||||||
@Entity
|
@Entity
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Table
|
@Table(
|
||||||
|
uniqueConstraints = {@UniqueConstraint(name = "uidx01_wf_instance", columnNames = {"wfInstanceId"})},
|
||||||
|
indexes = {
|
||||||
|
@Index(name = "idx01_wf_instance", columnList = "workflowId,status"),
|
||||||
|
@Index(name = "idx01_wf_instance", columnList = "appId,status,expectedTriggerTime")
|
||||||
|
}
|
||||||
|
)
|
||||||
public class WorkflowInstanceInfoDO {
|
public class WorkflowInstanceInfoDO {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -21,7 +21,9 @@ import java.util.Date;
|
|||||||
@Entity
|
@Entity
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Table(indexes = {@Index(columnList = "appId"), @Index(columnList = "workflowId")})
|
@Table(indexes = {
|
||||||
|
@Index(name = "idx01_workflow_node_info", columnList = "workflowId,gmtCreate")
|
||||||
|
})
|
||||||
public class WorkflowNodeInfoDO {
|
public class WorkflowNodeInfoDO {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -23,20 +23,20 @@ public class BriefInstanceInfo {
|
|||||||
*/
|
*/
|
||||||
private Long instanceId;
|
private Long instanceId;
|
||||||
/**
|
/**
|
||||||
* 总共执行的次数(用于重试判断)
|
* 总共执行的次数(用于重试判断)
|
||||||
*/
|
*/
|
||||||
private Long runningTimes;
|
private Long runningTimes;
|
||||||
|
|
||||||
|
|
||||||
public BriefInstanceInfo(Long appId,Long id, Long jobId, Long instanceId) {
|
public BriefInstanceInfo(Long appId, Long id, Long jobId, Long instanceId) {
|
||||||
this.appId = id;
|
this.appId = appId;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.jobId = jobId;
|
this.jobId = jobId;
|
||||||
this.instanceId = instanceId;
|
this.instanceId = instanceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BriefInstanceInfo(Long appId,Long id, Long jobId, Long instanceId, Long runningTimes) {
|
public BriefInstanceInfo(Long appId, Long id, Long jobId, Long instanceId, Long runningTimes) {
|
||||||
this.appId = id;
|
this.appId = appId;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.jobId = jobId;
|
this.jobId = jobId;
|
||||||
this.instanceId = instanceId;
|
this.instanceId = instanceId;
|
||||||
|
@ -33,9 +33,12 @@ public interface InstanceInfoRepository extends JpaRepository<InstanceInfoDO, Lo
|
|||||||
/**
|
/**
|
||||||
* 更新状态变更信息
|
* 更新状态变更信息
|
||||||
*
|
*
|
||||||
* @param instanceId 实例 ID
|
* @param lastReportTime 最近一次上报时间
|
||||||
* @param status 目标状态
|
* @param modifyTime 更新时间
|
||||||
* @param oldStatus 旧状态
|
* @param runningTimes 运行次数
|
||||||
|
* @param instanceId 实例 ID
|
||||||
|
* @param status 目标状态
|
||||||
|
* @param oldStatus 旧状态
|
||||||
* @return 更新记录数
|
* @return 更新记录数
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackOn = Exception.class)
|
@Transactional(rollbackOn = Exception.class)
|
||||||
@ -62,13 +65,6 @@ public interface InstanceInfoRepository extends JpaRepository<InstanceInfoDO, Lo
|
|||||||
int update4TriggerFailed(@Param("instanceId") long instanceId, @Param("status") int status, @Param("actualTriggerTime") long actualTriggerTime, @Param("finishedTime") long finishedTime, @Param("taskTrackerAddress") String taskTrackerAddress, @Param("result") String result, @Param("modifyTime") Date modifyTime);
|
int update4TriggerFailed(@Param("instanceId") long instanceId, @Param("status") int status, @Param("actualTriggerTime") long actualTriggerTime, @Param("finishedTime") long finishedTime, @Param("taskTrackerAddress") String taskTrackerAddress, @Param("result") String result, @Param("modifyTime") Date modifyTime);
|
||||||
|
|
||||||
|
|
||||||
@Transactional(rollbackOn = Exception.class)
|
|
||||||
@Modifying
|
|
||||||
@CanIgnoreReturnValue
|
|
||||||
@Query(value = "update InstanceInfoDO set expectedTriggerTime = :expectedTriggerTime, gmtModified = :modifyTime where instanceId = :instanceId and status = :status")
|
|
||||||
int updateExpectedTriggerTimeByInstanceIdAndStatus(@Param("instanceId") long instanceId, @Param("status") int status, @Param("expectedTriggerTime") long expectedTriggerTime, @Param("modifyTime") Date modifyTime);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新任务执行记录内容(DispatchService专用)
|
* 更新任务执行记录内容(DispatchService专用)
|
||||||
*
|
*
|
||||||
@ -77,6 +73,7 @@ public interface InstanceInfoRepository extends JpaRepository<InstanceInfoDO, Lo
|
|||||||
* @param actualTriggerTime 实际调度时间
|
* @param actualTriggerTime 实际调度时间
|
||||||
* @param taskTrackerAddress taskTracker 地址
|
* @param taskTrackerAddress taskTracker 地址
|
||||||
* @param modifyTime 更新时间
|
* @param modifyTime 更新时间
|
||||||
|
* @param oldStatus 旧状态
|
||||||
* @return 更新记录数量
|
* @return 更新记录数量
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackOn = Exception.class)
|
@Transactional(rollbackOn = Exception.class)
|
||||||
|
@ -20,13 +20,18 @@ public interface WorkflowInfoRepository extends JpaRepository<WorkflowInfoDO, Lo
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询指定 APP 下所有的工作流信息
|
* 查询指定 APP 下所有的工作流信息
|
||||||
|
*
|
||||||
* @param appId APP ID
|
* @param appId APP ID
|
||||||
* @return 该 APP 下的所有工作流信息
|
* @return 该 APP 下的所有工作流信息
|
||||||
*/
|
*/
|
||||||
List<WorkflowInfoDO> findByAppId(Long appId);
|
List<WorkflowInfoDO> findByAppId(Long appId);
|
||||||
|
|
||||||
/** 对外查询(list)三兄弟 */
|
/**
|
||||||
|
* 对外查询(list)三兄弟
|
||||||
|
*/
|
||||||
Page<WorkflowInfoDO> findByAppIdAndStatusNot(Long appId, int nStatus, Pageable pageable);
|
Page<WorkflowInfoDO> findByAppIdAndStatusNot(Long appId, int nStatus, Pageable pageable);
|
||||||
|
|
||||||
Page<WorkflowInfoDO> findByIdAndStatusNot(Long id, int nStatus, Pageable pageable);
|
Page<WorkflowInfoDO> findByIdAndStatusNot(Long id, int nStatus, Pageable pageable);
|
||||||
|
|
||||||
Page<WorkflowInfoDO> findByAppIdAndStatusNotAndWfNameLike(Long appId, int nStatus, String condition, Pageable pageable);
|
Page<WorkflowInfoDO> findByAppIdAndStatusNotAndWfNameLike(Long appId, int nStatus, String condition, Pageable pageable);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user