mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
[dev] support instanceInfo's complex query
This commit is contained in:
parent
0e32fbeeef
commit
f54ba4a078
@ -43,7 +43,7 @@ public class InstanceInfoDO {
|
|||||||
/**
|
/**
|
||||||
* 任务状态 {@link InstanceStatus}
|
* 任务状态 {@link InstanceStatus}
|
||||||
*/
|
*/
|
||||||
private int status;
|
private Integer status;
|
||||||
// 执行结果(允许存储稍大的结果)
|
// 执行结果(允许存储稍大的结果)
|
||||||
@Lob
|
@Lob
|
||||||
@Column(columnDefinition="TEXT")
|
@Column(columnDefinition="TEXT")
|
||||||
|
@ -2,8 +2,6 @@ package com.github.kfcfans.oms.server.persistence.core.repository;
|
|||||||
|
|
||||||
import com.github.kfcfans.oms.server.persistence.core.model.InstanceInfoDO;
|
import com.github.kfcfans.oms.server.persistence.core.model.InstanceInfoDO;
|
||||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Modifying;
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
@ -62,12 +60,6 @@ public interface InstanceInfoRepository extends JpaRepository<InstanceInfoDO, Lo
|
|||||||
|
|
||||||
InstanceInfoDO findByInstanceId(long instanceId);
|
InstanceInfoDO findByInstanceId(long instanceId);
|
||||||
|
|
||||||
// list 三兄弟
|
|
||||||
Page<InstanceInfoDO> findByAppIdAndType(long appId, int type, Pageable pageable);
|
|
||||||
Page<InstanceInfoDO> findByJobIdAndType(long jobId, int type, Pageable pageable);
|
|
||||||
// 只会有一条数据,只是为了统一
|
|
||||||
Page<InstanceInfoDO> findByInstanceIdAndType(long instanceId, int type, Pageable pageable);
|
|
||||||
|
|
||||||
// 数据统计
|
// 数据统计
|
||||||
long countByAppIdAndStatus(long appId, int status);
|
long countByAppIdAndStatus(long appId, int status);
|
||||||
long countByAppIdAndStatusAndGmtCreateAfter(long appId, int status, Date time);
|
long countByAppIdAndStatusAndGmtCreateAfter(long appId, int status, Date time);
|
||||||
|
@ -5,10 +5,10 @@ import com.github.kfcfans.oms.common.OmsException;
|
|||||||
import com.github.kfcfans.oms.common.TimeExpressionType;
|
import com.github.kfcfans.oms.common.TimeExpressionType;
|
||||||
import com.github.kfcfans.oms.common.request.http.SaveWorkflowRequest;
|
import com.github.kfcfans.oms.common.request.http.SaveWorkflowRequest;
|
||||||
import com.github.kfcfans.oms.common.response.WorkflowInfoDTO;
|
import com.github.kfcfans.oms.common.response.WorkflowInfoDTO;
|
||||||
import com.github.kfcfans.oms.server.common.utils.WorkflowDAGUtils;
|
|
||||||
import com.github.kfcfans.oms.server.common.SJ;
|
import com.github.kfcfans.oms.server.common.SJ;
|
||||||
import com.github.kfcfans.oms.server.common.constans.SwitchableStatus;
|
import com.github.kfcfans.oms.server.common.constans.SwitchableStatus;
|
||||||
import com.github.kfcfans.oms.server.common.utils.CronExpression;
|
import com.github.kfcfans.oms.server.common.utils.CronExpression;
|
||||||
|
import com.github.kfcfans.oms.server.common.utils.WorkflowDAGUtils;
|
||||||
import com.github.kfcfans.oms.server.persistence.core.model.WorkflowInfoDO;
|
import com.github.kfcfans.oms.server.persistence.core.model.WorkflowInfoDO;
|
||||||
import com.github.kfcfans.oms.server.persistence.core.repository.WorkflowInfoRepository;
|
import com.github.kfcfans.oms.server.persistence.core.repository.WorkflowInfoRepository;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
@ -58,7 +58,9 @@ public class WorkflowService {
|
|||||||
wf.setStatus(req.isEnable() ? SwitchableStatus.ENABLE.getV() : SwitchableStatus.DISABLE.getV());
|
wf.setStatus(req.isEnable() ? SwitchableStatus.ENABLE.getV() : SwitchableStatus.DISABLE.getV());
|
||||||
wf.setTimeExpressionType(req.getTimeExpressionType().getV());
|
wf.setTimeExpressionType(req.getTimeExpressionType().getV());
|
||||||
|
|
||||||
wf.setNotifyUserIds(SJ.commaJoiner.join(req.getNotifyUserIds()));
|
if (req.getNotifyUserIds() != null) {
|
||||||
|
wf.setNotifyUserIds(SJ.commaJoiner.join(req.getNotifyUserIds()));
|
||||||
|
}
|
||||||
|
|
||||||
// 计算 NextTriggerTime
|
// 计算 NextTriggerTime
|
||||||
if (req.getTimeExpressionType() == TimeExpressionType.CRON) {
|
if (req.getTimeExpressionType() == TimeExpressionType.CRON) {
|
||||||
|
@ -20,6 +20,7 @@ import com.github.kfcfans.oms.server.web.response.InstanceInfoVO;
|
|||||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.data.domain.Example;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
@ -110,18 +111,12 @@ public class InstanceController {
|
|||||||
Sort sort = Sort.by(Sort.Direction.DESC, "gmtModified");
|
Sort sort = Sort.by(Sort.Direction.DESC, "gmtModified");
|
||||||
PageRequest pageable = PageRequest.of(request.getIndex(), request.getPageSize(), sort);
|
PageRequest pageable = PageRequest.of(request.getIndex(), request.getPageSize(), sort);
|
||||||
|
|
||||||
// 查询全部数据
|
InstanceInfoDO queryEntity = new InstanceInfoDO();
|
||||||
if (request.getJobId() == null && request.getInstanceId() == null) {
|
BeanUtils.copyProperties(request, queryEntity);
|
||||||
return ResultDTO.success(convertPage(instanceInfoRepository.findByAppIdAndType(request.getAppId(), request.getType().getV(), pageable)));
|
queryEntity.setType(request.getType().getV());
|
||||||
}
|
|
||||||
|
|
||||||
// 根据JobId查询
|
Page<InstanceInfoDO> pageResult = instanceInfoRepository.findAll(Example.of(queryEntity), pageable);
|
||||||
if (request.getJobId() != null) {
|
return ResultDTO.success(convertPage(pageResult));
|
||||||
return ResultDTO.success(convertPage(instanceInfoRepository.findByJobIdAndType(request.getJobId(), request.getType().getV(), pageable)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据InstanceId查询
|
|
||||||
return ResultDTO.success(convertPage(instanceInfoRepository.findByInstanceIdAndType(request.getInstanceId(), request.getType().getV(), pageable)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PageResult<InstanceInfoVO> convertPage(Page<InstanceInfoDO> page) {
|
private PageResult<InstanceInfoVO> convertPage(Page<InstanceInfoDO> page) {
|
||||||
|
@ -44,6 +44,12 @@ public class WorkflowController {
|
|||||||
return ResultDTO.success(null);
|
return ResultDTO.success(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/enable")
|
||||||
|
public ResultDTO<Void> enableWorkflow(Long workflowId, Long appId) {
|
||||||
|
workflowService.enableWorkflow(workflowId, appId);
|
||||||
|
return ResultDTO.success(null);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/delete")
|
@GetMapping("/delete")
|
||||||
public ResultDTO<Void> deleteWorkflow(Long workflowId, Long appId) {
|
public ResultDTO<Void> deleteWorkflow(Long workflowId, Long appId) {
|
||||||
workflowService.deleteWorkflow(workflowId, appId);
|
workflowService.deleteWorkflow(workflowId, appId);
|
||||||
|
@ -23,4 +23,5 @@ public class QueryInstanceRequest {
|
|||||||
private InstanceType type;
|
private InstanceType type;
|
||||||
private Long instanceId;
|
private Long instanceId;
|
||||||
private Long jobId;
|
private Long jobId;
|
||||||
|
private Long wfInstanceId;
|
||||||
}
|
}
|
||||||
|
@ -153,6 +153,7 @@ public class OhMyWorker implements ApplicationContextAware, InitializingBean, Di
|
|||||||
}catch (OmsException oe) {
|
}catch (OmsException oe) {
|
||||||
throw oe;
|
throw oe;
|
||||||
}catch (Exception ignore) {
|
}catch (Exception ignore) {
|
||||||
|
log.warn("[OhMyWorker] assert appName by url({}) failed, please check the server address.", realUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.error("[OhMyWorker] no available server in {}.", config.getServerAddress());
|
log.error("[OhMyWorker] no available server in {}.", config.getServerAddress());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user