use of org.hisp.dhis.analytics.AnalyticsTableService in project dhis2-core by dhis2.
the class DefaultAnalyticsTableGenerator method generateTables.
// -------------------------------------------------------------------------
// Implementation
// -------------------------------------------------------------------------
@Override
public void generateTables(Integer lastYears, TaskId taskId, Set<AnalyticsTableType> skipTableTypes, boolean skipResourceTables) {
final Date startTime = new Date();
final Clock clock = new Clock(log).startClock();
final Set<AnalyticsTableType> skipTypes = CollectionUtils.emptyIfNull(skipTableTypes);
final Set<AnalyticsTableType> availableTypes = analyticsTableServices.stream().map(AnalyticsTableService::getAnalyticsTableType).collect(Collectors.toSet());
log.info(String.format("Found %d analytics table types: %s", availableTypes.size(), availableTypes));
log.info(String.format("Skip %d analytics table types: %s", skipTypes.size(), skipTypes));
try {
notifier.clear(taskId).notify(taskId, "Analytics table update process started");
if (!skipResourceTables) {
notifier.notify(taskId, "Updating resource tables");
generateResourceTables();
}
for (AnalyticsTableService service : analyticsTableServices) {
AnalyticsTableType tableType = service.getAnalyticsTableType();
if (!skipTypes.contains(tableType)) {
notifier.notify(taskId, "Updating tables: " + tableType);
service.update(lastYears, taskId);
}
}
clock.logTime("Analytics tables updated");
notifier.notify(taskId, INFO, "Analytics tables updated: " + clock.time(), true);
} catch (RuntimeException ex) {
notifier.notify(taskId, ERROR, "Process failed: " + ex.getMessage(), true);
messageService.sendSystemErrorNotification("Analytics table process failed", ex);
throw ex;
}
systemSettingManager.saveSystemSetting(SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE, startTime);
systemSettingManager.saveSystemSetting(SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_RUNTIME, DateUtils.getPrettyInterval(clock.getSplitTime()));
}
use of org.hisp.dhis.analytics.AnalyticsTableService in project dhis2-core by dhis2.
the class DefaultAnalyticsTableGenerator method generateTables.
// TODO introduce last successful timestamps per table type
@Override
public void generateTables(AnalyticsTableUpdateParams params, JobProgress progress) {
final Clock clock = new Clock(log).startClock();
final Date lastSuccessfulUpdate = systemSettingManager.getDateSetting(SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE);
final Set<AnalyticsTableType> skipTypes = CollectionUtils.emptyIfNull(params.getSkipTableTypes());
final Set<AnalyticsTableType> availableTypes = analyticsTableServices.stream().map(AnalyticsTableService::getAnalyticsTableType).collect(Collectors.toSet());
params = AnalyticsTableUpdateParams.newBuilder(params).withLastSuccessfulUpdate(lastSuccessfulUpdate).build();
log.info("Found {} analytics table types: {}", availableTypes.size(), availableTypes);
log.info("Analytics table update: {}", params);
log.info("Last successful analytics table update: '{}'", getLongDateString(lastSuccessfulUpdate));
progress.startingProcess("Analytics table update process started");
try {
if (!params.isSkipResourceTables() && !params.isLatestUpdate()) {
generateResourceTablesInternal(progress);
}
for (AnalyticsTableService service : analyticsTableServices) {
AnalyticsTableType tableType = service.getAnalyticsTableType();
if (!skipTypes.contains(tableType)) {
service.update(params, progress);
}
}
clock.logTime("Analytics tables updated");
progress.completedProcess("Analytics tables updated: " + clock.time());
} catch (Exception ex) {
log.error("Analytics table process failed: " + DebugUtils.getStackTrace(ex), ex);
progress.failedProcess(ex);
messageService.sendSystemErrorNotification("Analytics table process failed", ex);
throw ex;
}
if (params.isLatestUpdate()) {
systemSettingManager.saveSystemSetting(SettingKey.LAST_SUCCESSFUL_LATEST_ANALYTICS_PARTITION_UPDATE, params.getStartTime());
systemSettingManager.saveSystemSetting(SettingKey.LAST_SUCCESSFUL_LATEST_ANALYTICS_PARTITION_RUNTIME, clock.time());
} else {
systemSettingManager.saveSystemSetting(SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE, params.getStartTime());
systemSettingManager.saveSystemSetting(SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_RUNTIME, clock.time());
}
analyticsCache.invalidateAll();
}
Aggregations