Search in sources :

Example 1 with ContinuousAnalyticsJobParameters

use of org.hisp.dhis.scheduling.parameters.ContinuousAnalyticsJobParameters in project dhis2-core by dhis2.

the class SchedulingManagerTest method createFixedDelayJobConfiguration.

private static JobConfiguration createFixedDelayJobConfiguration() {
    JobConfiguration configuration = new JobConfiguration("delay", JobType.CONTINUOUS_ANALYTICS_TABLE, getDailyCronExpression(0, 0), new ContinuousAnalyticsJobParameters());
    // only jobs with ID get scheduled
    configuration.setUid(generateUid());
    configuration.setDelay(1);
    return configuration;
}
Also used : ContinuousAnalyticsJobParameters(org.hisp.dhis.scheduling.parameters.ContinuousAnalyticsJobParameters)

Example 2 with ContinuousAnalyticsJobParameters

use of org.hisp.dhis.scheduling.parameters.ContinuousAnalyticsJobParameters in project dhis2-core by dhis2.

the class JobConfigurationObjectBundleHookTest method validateDelayForFixedIntervalTypeJobs.

@Test
void validateDelayForFixedIntervalTypeJobs() {
    String jobConfigUid = "o8kG3Qk3nG3";
    JobConfiguration contAnalyticsTableJobConfig = new JobConfiguration();
    contAnalyticsTableJobConfig.setUid(jobConfigUid);
    contAnalyticsTableJobConfig.setJobType(JobType.CONTINUOUS_ANALYTICS_TABLE);
    Mockito.when(jobConfigurationService.getJobConfigurationByUid(Mockito.eq(jobConfigUid))).thenReturn(contAnalyticsTableJobConfig);
    Mockito.when(jobService.getJob(Mockito.eq(JobType.CONTINUOUS_ANALYTICS_TABLE))).thenReturn(job);
    JobConfiguration jobConfiguration = new JobConfiguration();
    jobConfiguration.setUid(jobConfigUid);
    jobConfiguration.setJobType(JobType.CONTINUOUS_ANALYTICS_TABLE);
    jobConfiguration.setJobParameters(new ContinuousAnalyticsJobParameters(1, null, null));
    List<ErrorReport> errorReports = hook.validate(jobConfiguration, null);
    Assertions.assertEquals(1, errorReports.size());
    Assertions.assertEquals(ErrorCode.E7007, errorReports.get(0).getErrorCode());
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ContinuousAnalyticsJobParameters(org.hisp.dhis.scheduling.parameters.ContinuousAnalyticsJobParameters) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 3 with ContinuousAnalyticsJobParameters

use of org.hisp.dhis.scheduling.parameters.ContinuousAnalyticsJobParameters in project dhis2-core by dhis2.

the class ContinuousAnalyticsTableJob method execute.

@Override
public void execute(JobConfiguration jobConfiguration, JobProgress progress) {
    ContinuousAnalyticsJobParameters parameters = (ContinuousAnalyticsJobParameters) jobConfiguration.getJobParameters();
    Integer fullUpdateHourOfDay = ObjectUtils.firstNonNull(parameters.getFullUpdateHourOfDay(), DEFAULT_HOUR_OF_DAY);
    Date now = new Date();
    Date defaultNextFullUpdate = DateUtils.getNextDate(fullUpdateHourOfDay, now);
    Date nextFullUpdate = systemSettingManager.getSystemSetting(SettingKey.NEXT_ANALYTICS_TABLE_UPDATE, defaultNextFullUpdate);
    log.info("Starting continuous analytics table update, current time: '{}', default next full update: '{}', next full update: '{}'", getLongDateString(now), getLongDateString(defaultNextFullUpdate), getLongDateString(nextFullUpdate));
    Preconditions.checkNotNull(nextFullUpdate);
    if (now.after(nextFullUpdate)) {
        log.info("Performing full analytics table update");
        AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withLastYears(parameters.getLastYears()).withSkipResourceTables(false).withSkipTableTypes(parameters.getSkipTableTypes()).withJobId(jobConfiguration).withStartTime(now).build();
        try {
            analyticsTableGenerator.generateTables(params, progress);
        } finally {
            Date nextUpdate = DateUtils.getNextDate(fullUpdateHourOfDay, now);
            systemSettingManager.saveSystemSetting(SettingKey.NEXT_ANALYTICS_TABLE_UPDATE, nextUpdate);
            log.info("Next full analytics table update: '{}'", getLongDateString(nextUpdate));
        }
    } else {
        log.info("Performing latest analytics table partition update");
        AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withLatestPartition().withSkipResourceTables(true).withSkipTableTypes(parameters.getSkipTableTypes()).withJobId(jobConfiguration).withStartTime(now).build();
        analyticsTableGenerator.generateTables(params, progress);
    }
}
Also used : ContinuousAnalyticsJobParameters(org.hisp.dhis.scheduling.parameters.ContinuousAnalyticsJobParameters) AnalyticsTableUpdateParams(org.hisp.dhis.analytics.AnalyticsTableUpdateParams) Date(java.util.Date)

Aggregations

ContinuousAnalyticsJobParameters (org.hisp.dhis.scheduling.parameters.ContinuousAnalyticsJobParameters)3 Date (java.util.Date)1 AnalyticsTableUpdateParams (org.hisp.dhis.analytics.AnalyticsTableUpdateParams)1 ErrorReport (org.hisp.dhis.feedback.ErrorReport)1 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)1 Test (org.junit.jupiter.api.Test)1