학습 실패여부 확인 기능 추가
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.kamco.cd.training.postgres.core;
|
||||
|
||||
import com.kamco.cd.training.common.exception.CustomApiException;
|
||||
import com.kamco.cd.training.postgres.entity.ModelTrainJobEntity;
|
||||
import com.kamco.cd.training.postgres.repository.train.ModelTrainJobRepository;
|
||||
import com.kamco.cd.training.train.dto.ModelTrainJobDto;
|
||||
@@ -9,6 +10,7 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -61,7 +63,7 @@ public class ModelTrainJobCoreService {
|
||||
ModelTrainJobEntity job =
|
||||
modelTrainJobRepository
|
||||
.findById(jobId)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Job not found: " + jobId));
|
||||
.orElseThrow(() -> new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND));
|
||||
|
||||
job.setStatusCd("RUNNING");
|
||||
job.setContainerName(containerName);
|
||||
@@ -87,7 +89,7 @@ public class ModelTrainJobCoreService {
|
||||
ModelTrainJobEntity job =
|
||||
modelTrainJobRepository
|
||||
.findById(jobId)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Job not found: " + jobId));
|
||||
.orElseThrow(() -> new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND));
|
||||
|
||||
job.setStatusCd("SUCCESS");
|
||||
job.setExitCode(exitCode);
|
||||
@@ -106,7 +108,7 @@ public class ModelTrainJobCoreService {
|
||||
ModelTrainJobEntity job =
|
||||
modelTrainJobRepository
|
||||
.findById(jobId)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Job not found: " + jobId));
|
||||
.orElseThrow(() -> new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND));
|
||||
|
||||
job.setStatusCd("FAILED");
|
||||
job.setExitCode(exitCode);
|
||||
@@ -122,7 +124,7 @@ public class ModelTrainJobCoreService {
|
||||
ModelTrainJobEntity job =
|
||||
modelTrainJobRepository
|
||||
.findById(jobId)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Job not found: " + jobId));
|
||||
.orElseThrow(() -> new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND));
|
||||
|
||||
job.setStatusCd("STOPPED");
|
||||
job.setFinishedDttm(ZonedDateTime.now());
|
||||
@@ -133,7 +135,7 @@ public class ModelTrainJobCoreService {
|
||||
ModelTrainJobEntity job =
|
||||
modelTrainJobRepository
|
||||
.findByContainerName(containerName)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Job not found: " + containerName));
|
||||
.orElseThrow(() -> new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND));
|
||||
|
||||
job.setCurrentEpoch(epoch);
|
||||
|
||||
@@ -143,4 +145,17 @@ public class ModelTrainJobCoreService {
|
||||
public void insertModelTestTrainingRun(Long modelId, Long jobId, int epoch) {
|
||||
modelTrainJobRepository.insertModelTestTrainingRun(modelId, jobId, epoch);
|
||||
}
|
||||
|
||||
/**
|
||||
* 실행중인 학습이 있는지 조회
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ModelTrainJobDto findRunningJobs() {
|
||||
ModelTrainJobEntity entity = modelTrainJobRepository.findRunningJobs().orElse(null);
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
return entity.toDto();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,4 +11,6 @@ public interface ModelTrainJobRepositoryCustom {
|
||||
Optional<ModelTrainJobEntity> findByContainerName(String containerName);
|
||||
|
||||
void insertModelTestTrainingRun(Long modelId, Long jobId, int epoch);
|
||||
|
||||
Optional<ModelTrainJobEntity> findRunningJobs();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.kamco.cd.training.postgres.repository.train;
|
||||
|
||||
import static com.kamco.cd.training.postgres.entity.QModelTestTrainingRunEntity.modelTestTrainingRunEntity;
|
||||
import static com.kamco.cd.training.postgres.entity.QModelTrainJobEntity.modelTrainJobEntity;
|
||||
|
||||
import com.kamco.cd.training.common.enums.JobStatusType;
|
||||
import com.kamco.cd.training.common.enums.JobType;
|
||||
import com.kamco.cd.training.postgres.entity.ModelTrainJobEntity;
|
||||
import com.kamco.cd.training.postgres.entity.QModelTrainJobEntity;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
@@ -21,7 +24,7 @@ public class ModelTrainJobRepositoryImpl implements ModelTrainJobRepositoryCusto
|
||||
/** modelId의 attempt_no 최대값. (없으면 0) */
|
||||
@Override
|
||||
public int findMaxAttemptNo(Long modelId) {
|
||||
QModelTrainJobEntity j = QModelTrainJobEntity.modelTrainJobEntity;
|
||||
QModelTrainJobEntity j = modelTrainJobEntity;
|
||||
|
||||
Integer max =
|
||||
queryFactory.select(j.attemptNo.max()).from(j).where(j.modelId.eq(modelId)).fetchOne();
|
||||
@@ -35,7 +38,7 @@ public class ModelTrainJobRepositoryImpl implements ModelTrainJobRepositoryCusto
|
||||
*/
|
||||
@Override
|
||||
public Optional<ModelTrainJobEntity> findLatestByModelId(Long modelId) {
|
||||
QModelTrainJobEntity j = QModelTrainJobEntity.modelTrainJobEntity;
|
||||
QModelTrainJobEntity j = modelTrainJobEntity;
|
||||
|
||||
ModelTrainJobEntity job =
|
||||
queryFactory.selectFrom(j).where(j.modelId.eq(modelId)).orderBy(j.id.desc()).fetchFirst();
|
||||
@@ -45,7 +48,7 @@ public class ModelTrainJobRepositoryImpl implements ModelTrainJobRepositoryCusto
|
||||
|
||||
@Override
|
||||
public Optional<ModelTrainJobEntity> findByContainerName(String containerName) {
|
||||
QModelTrainJobEntity j = QModelTrainJobEntity.modelTrainJobEntity;
|
||||
QModelTrainJobEntity j = modelTrainJobEntity;
|
||||
|
||||
ModelTrainJobEntity job =
|
||||
queryFactory
|
||||
@@ -78,4 +81,20 @@ public class ModelTrainJobRepositoryImpl implements ModelTrainJobRepositoryCusto
|
||||
.values(modelId, nextAttemptNo, jobId, epoch)
|
||||
.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ModelTrainJobEntity> findRunningJobs() {
|
||||
return Optional.ofNullable(
|
||||
queryFactory
|
||||
.select(modelTrainJobEntity)
|
||||
.from(modelTrainJobEntity)
|
||||
.where(
|
||||
modelTrainJobEntity
|
||||
.statusCd
|
||||
.eq(JobStatusType.RUNNING.getId())
|
||||
.and(modelTrainJobEntity.jobType.eq(JobType.TRAIN.getId())))
|
||||
.orderBy(modelTrainJobEntity.id.desc())
|
||||
.limit(1)
|
||||
.fetchOne());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user