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;
}
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());
}
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);
}
}
Aggregations