Search in sources :

Example 1 with Job

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;
    }
}
Also used : JobStatus(gov.cms.ab2d.common.model.JobStatus) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Job(gov.cms.ab2d.common.model.Job) JobOutput(gov.cms.ab2d.common.model.JobOutput) JobOutput(gov.cms.ab2d.common.model.JobOutput)

Example 2 with Job

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);
    }
}
Also used : LocalTime(java.time.LocalTime) OffsetDateTime(java.time.OffsetDateTime) Job(gov.cms.ab2d.common.model.Job) Contract(gov.cms.ab2d.common.model.Contract) LocalDate(java.time.LocalDate) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with Job

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);
    }
}
Also used : Job(gov.cms.ab2d.common.model.Job) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with Job

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);
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) Job(gov.cms.ab2d.common.model.Job) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with Job

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);
}
Also used : ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) PdpClientDTO(gov.cms.ab2d.common.dto.PdpClientDTO) ContractToContractCoverageMapping(gov.cms.ab2d.worker.config.ContractToContractCoverageMapping) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Job(gov.cms.ab2d.common.model.Job) PdpClient(gov.cms.ab2d.common.model.PdpClient) BFDClient(gov.cms.ab2d.bfd.client.BFDClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Job (gov.cms.ab2d.common.model.Job)67 Test (org.junit.jupiter.api.Test)39 DisplayName (org.junit.jupiter.api.DisplayName)31 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)21 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 OffsetDateTime (java.time.OffsetDateTime)15 JobOutput (gov.cms.ab2d.common.model.JobOutput)9 CoveragePagingRequest (gov.cms.ab2d.coverage.model.CoveragePagingRequest)9 CoveragePagingResult (gov.cms.ab2d.coverage.model.CoveragePagingResult)9 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)8 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)6 Map (java.util.Map)5 Contract (gov.cms.ab2d.common.model.Contract)4 PdpClient (gov.cms.ab2d.common.model.PdpClient)4 ZonedDateTime (java.time.ZonedDateTime)4 Transactional (org.springframework.transaction.annotation.Transactional)4 ContractToContractCoverageMapping (gov.cms.ab2d.worker.config.ContractToContractCoverageMapping)3 List (java.util.List)3 Trace (com.newrelic.api.agent.Trace)2 PdpClientService (gov.cms.ab2d.common.service.PdpClientService)2