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