use of gov.cms.ab2d.common.model.Job in project ab2d by CMSgov.
the class JobUtil method isJobDone.
/**
* A job is done if the status is either CANCELLED or FAILED
* If a job status is SUCCESSFUL, it is done if all files have been downloaded or they have expired
*
* @param job
* @return
*/
public static boolean isJobDone(Job job) {
try {
// Job is still in progress
if (job == null || job.getStatus() == null || job.getStatus() == JobStatus.IN_PROGRESS || job.getStatus() == JobStatus.SUBMITTED) {
return false;
}
// Job has finished but was not successful
if (job.getStatus() == JobStatus.CANCELLED || job.getStatus() == JobStatus.FAILED) {
return true;
}
// Job has expired, it's done.
if (job.getExpiresAt() != null && job.getExpiresAt().isBefore(OffsetDateTime.now())) {
return true;
}
// If it hasn't expired, look to see if all files have been downloaded, if so, it's done
List<JobOutput> jobOutputs = job.getJobOutputs();
if (jobOutputs == null || jobOutputs.isEmpty()) {
return false;
}
JobOutput aRemaining = jobOutputs.stream().filter(c -> c.getError() == null || !c.getError()).filter(c -> !c.getDownloaded()).findAny().orElse(null);
return aRemaining == null;
} catch (Exception ex) {
// Logging should never break anything
String jobId = job.getJobUuid();
log.error("Unable to determine if job " + jobId + " is done", ex);
return false;
}
}
use of gov.cms.ab2d.common.model.Job in project ab2d by CMSgov.
the class CoverageDriverTest method availableCoverageWhenSinceContainsOnlySuccessful.
/**
* The since date is only relevant for claims data not enrollment data. So even though the since date
* is set the enrollment data must all be up to date before a job can start.
*/
@DisplayName("Do not start an eob job if periods before since are being worked on. Ignore since.")
@Test
void availableCoverageWhenSinceContainsOnlySuccessful() {
Job job = new Job();
job.setCreatedAt(OffsetDateTime.now());
Contract temp = contractRepo.findContractByContractNumber(contractForCoverageDTO.getContractNumber()).get();
job.setContractNumber(temp.getContractNumber());
OffsetDateTime since = OffsetDateTime.of(LocalDate.of(2020, 3, 1), LocalTime.of(0, 0, 0), AB2D_ZONE.getRules().getOffset(Instant.now()));
try {
changeStatus(contractForCoverageDTO, since, CoverageJobStatus.SUCCESSFUL);
LocalDate startMonth = LocalDate.of(2020, 3, 1);
LocalTime startDay = LocalTime.of(0, 0, 0);
job.setSince(OffsetDateTime.of(startMonth, startDay, AB2D_ZONE.getRules().getOffset(Instant.now())));
boolean inProgressBeginningMonth = driver.isCoverageAvailable(job, contract.toDTO());
assertFalse(inProgressBeginningMonth, "eob searches should run when only month after since is successful");
LocalDate endMonth = LocalDate.of(2020, 3, 31);
LocalTime endDay = LocalTime.of(23, 59, 59);
job.setSince(OffsetDateTime.of(endMonth, endDay, AB2D_ZONE.getRules().getOffset(Instant.now())));
boolean inProgressEndMonth = driver.isCoverageAvailable(job, contract.toDTO());
assertFalse(inProgressEndMonth, "eob searches should run when only month after since is successful");
} catch (InterruptedException | CoverageDriverException exception) {
fail("could not check for available coverage", exception);
}
}
use of gov.cms.ab2d.common.model.Job in project ab2d by CMSgov.
the class CoverageDriverTest method availableCoverageWhenNeverSearched.
@DisplayName("Do not start an eob job if any relevant coverage period has never had data pulled for it")
@Test
void availableCoverageWhenNeverSearched() {
Job job = new Job();
job.setContractNumber(contract.getContractNumber());
try {
boolean noCoverageStatuses = driver.isCoverageAvailable(job, contract.toDTO());
assertFalse(noCoverageStatuses, "eob searches should not run when a" + " coverage period has no information");
} catch (InterruptedException | CoverageDriverException exception) {
fail("could not check for available coverage", exception);
}
}
use of gov.cms.ab2d.common.model.Job in project ab2d by CMSgov.
the class CoverageDriverTest method availableCoverageWhenAllSuccessful.
@DisplayName("Do start an eob job if all coverage periods are in progress")
@Test
void availableCoverageWhenAllSuccessful() {
Job job = new Job();
job.setContractNumber(contractForCoverageDTO.getContractNumber());
job.setCreatedAt(OffsetDateTime.now());
try {
changeStatus(contractForCoverageDTO, AB2D_EPOCH.toOffsetDateTime(), CoverageJobStatus.SUCCESSFUL);
// Make sure that there is a lastSuccessfulJob
ZonedDateTime now = ZonedDateTime.now(AB2D_ZONE);
CoveragePeriod currentMonth = coverageService.getCoveragePeriod(contractForCoverageDTO, now.getMonthValue(), now.getYear());
currentMonth.setLastSuccessfulJob(OffsetDateTime.now().plusHours(2));
currentMonth.setStatus(CoverageJobStatus.SUCCESSFUL);
coveragePeriodRepo.saveAndFlush(currentMonth);
boolean submittedCoverageStatus = driver.isCoverageAvailable(job, contract.toDTO());
assertTrue(submittedCoverageStatus, "eob searches should not run if a " + "coverage period is submitted");
} catch (InterruptedException | CoverageDriverException exception) {
fail("could not check for available coverage", exception);
}
}
use of gov.cms.ab2d.common.model.Job in project ab2d by CMSgov.
the class CoverageDriverTest method before.
@BeforeEach
void before() {
mapping = new ContractToContractCoverageMapping();
// Set properties values in database
addPropertiesTableValues();
contract = dataSetup.setupContract("TST-12", AB2D_EPOCH.toOffsetDateTime());
contract1 = dataSetup.setupContract("TST-45", AB2D_EPOCH.toOffsetDateTime());
contractForCoverageDTO = new ContractForCoverageDTO("TST-12", AB2D_EPOCH.toOffsetDateTime(), ContractForCoverageDTO.ContractType.NORMAL);
contractForCoverageDTO1 = new ContractForCoverageDTO("TST-45", AB2D_EPOCH.toOffsetDateTime(), ContractForCoverageDTO.ContractType.NORMAL);
contractRepo.saveAndFlush(contract);
january = coverageDataSetup.createCoveragePeriod(contract.getContractNumber(), 1, 2020);
february = coverageDataSetup.createCoveragePeriod(contract.getContractNumber(), 2, 2020);
march = coverageDataSetup.createCoveragePeriod(contract.getContractNumber(), 3, 2020);
PdpClientDTO contractPdpClient = createClient(contract, "TST-12", SPONSOR_ROLE);
pdpClientService.createClient(contractPdpClient);
dataSetup.queueForCleanup(pdpClientService.getClientById("TST-12"));
PdpClient pdpClient = dataSetup.setupPdpClient(List.of());
job = new Job();
job.setContractNumber(contract.getContractNumber());
job.setJobUuid("unique");
job.setOrganization(pdpClient.getOrganization());
job.setStatus(gov.cms.ab2d.common.model.JobStatus.SUBMITTED);
job.setCreatedAt(OffsetDateTime.now());
job.setFhirVersion(STU3);
jobRepo.saveAndFlush(job);
dataSetup.queueForCleanup(job);
bfdClient = mock(BFDClient.class);
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setMaxPoolSize(6);
taskExecutor.setCorePoolSize(3);
taskExecutor.initialize();
processor = new CoverageProcessorImpl(coverageService, bfdClient, taskExecutor, MAX_ATTEMPTS, contractWorkerClient);
driver = new CoverageDriverImpl(coverageSearchRepo, pdpClientService, coverageService, propertiesService, processor, searchLock, contractToContractCoverageMapping);
}
Aggregations