@Transactional @Override public void sendScheduledNotificationsForDay( Date notificationDate ) { Clock clock = new Clock( log ).startClock() .logTime( "Processing ProgramStageNotification messages" ); List<ProgramNotificationTemplate> scheduledTemplates = getScheduledTemplates(); int totalMessageCount = 0; for ( ProgramNotificationTemplate template : scheduledTemplates ) { MessageBatch batch = createScheduledMessageBatchForDay( template, notificationDate ); sendAll( batch ); totalMessageCount += batch.messageCount(); } clock.logTime( String.format( "Created and sent %d messages in %s", totalMessageCount, clock.time() ) ); }
public SynchronizationResult syncCompleteness() { if ( !SyncUtils.testServerAvailability( systemSettingManager, restTemplate ).isAvailable() ) { return SynchronizationResult.newFailureResultWithMessage( "Completeness Synchronisation failed. Remote " + "server is unavailable." ); } final Clock clock = new Clock( log ) .startClock() .logTime( "Starting Completeness Synchronisation job." ); // --------------------------------------------------------------------- // Set time for last success to start of process to make data saved // subsequently part of next synch process without being ignored // --------------------------------------------------------------------- ImportSummary importSummary; try { importSummary = synchronizationManager.executeDataSetCompletenessPush(); if ( checkSummaryStatus( importSummary, SyncEndpoint.COMPLETE_DATA_SET_REGISTRATIONS ) ) { clock.logTime( "SUCCESS! Completeness Synchronisation job is done. It took" ); setLastDataValueSynchronizationSuccess( new Date( clock.getStartTime() ) ); return SynchronizationResult.newSuccessResultWithMessage( "Completeness Synchronisation done. It took " + clock.getTime() + " ms." ); } } catch ( Exception ex ) { log.error( "Exception happened while trying to completeness push " + ex.getMessage(), ex ); } return SynchronizationResult.newFailureResultWithMessage( "Completeness Synchronisation failed."); }
@Override public void execute( JobConfiguration jobConfiguration ) { final int cpuCores = SystemUtils.getCpuCores(); Clock clock = new Clock().startClock().logTime( "Aggregate process started, number of CPU cores: " + cpuCores + ", " + SystemUtils.getMemoryString() ); clock.logTime( "Starting to send messages in outbound" ); notifier.notify( jobConfiguration, INFO, "Start to send messages in outbound", true ); sendMessages(); clock.logTime( "Sending messages in outbound completed" ); notifier.notify( jobConfiguration, INFO, "Sending messages in outbound completed", true ); }
@Override public void execute( JobConfiguration jobConfiguration ) { final Clock clock = new Clock().startClock(); notifier.notify( jobConfiguration, "Generating and sending scheduled program notifications" ); try { runInternal(); notifier.notify( jobConfiguration, NotificationLevel.INFO, "Generated and sent scheduled program notifications: " + clock.time(), true ); } catch ( RuntimeException ex ) { notifier.notify( jobConfiguration, NotificationLevel.ERROR, "Process failed: " + ex.getMessage(), true ); messageService.sendSystemErrorNotification( "Generating and sending scheduled program notifications failed", ex ); throw ex; } }
public Collection<ValidationResult> validationAnalysis( ValidationAnalysisParams parameters) { Clock clock = new Clock( log ).startClock().logTime( "Starting validation analysis" + ( parameters.getOrgUnit() == null ? "" : " for orgUnit " + parameters.getOrgUnit().getUid() + ( parameters.isIncludeOrgUnitDescendants() ? " with descendants" : "" ) ) + ", " + ( parameters.getPeriods().size() == 1 ? "period " + Iterables.getOnlyElement( parameters.getPeriods() ).getIsoDate() : parameters.getPeriods().size() + " periods" ) + ", " + parameters.getRules().size() + " rules" + ( parameters.isPersistResults() ? ", persisting results" : "" ) + ( parameters.isSendNotifications() ? ", sending notifications" : "" ) ); ValidationRunContext context = getValidationContext( parameters ); clock.logTime( "Initialized validation analysis" ); Collection<ValidationResult> results = Validator.validate( context, applicationContext, analyticsService ); if ( context.isPersistResults() ) { validationResultService.saveValidationResults( context.getValidationResults() ); } clock.logTime( "Finished validation analysis, " + context.getValidationResults().size() + " results").stop(); if ( context.isSendNotifications() ) { notificationService.sendNotifications( Sets.newHashSet( results ) ); } return results; }
final Clock clock = new Clock().startClock(); try
/** * Method which calls the execute method in the job. The job will run in this thread and finish, either with success * or with an exception. * * @param jobConfiguration the configuration to execute * @param schedulingManager a reference to the scheduling manager * @param clock refers to start time * @throws Exception if the job fails */ private void executeJob( JobConfiguration jobConfiguration, SchedulingManager schedulingManager, Clock clock ) throws Exception { log.debug( "Job '" + jobConfiguration.getName() + "' started" ); schedulingManager.getJob( jobConfiguration.getJobType() ).execute( jobConfiguration ); log.debug( "Job '" + jobConfiguration.getName() + "' executed successfully. Time used: " + clock.time() ); } }
Clock clock = new Clock( log ).startClock() .logTime( String.format( "Creating notifications for %d validation results", validationResults.size() ) ); clock.logTime( String .format( "Sending %d %s notification(s)", entry.getValue().size(), entry.getKey().getDescription() ) ); clock.logTime( "Done sending validation notifications" );
@Override public void generateResourceTables( JobConfiguration jobId ) { final Clock clock = new Clock().startClock(); notifier.notify( jobId, "Generating resource tables" ); try { generateResourceTables(); notifier.notify( jobId, INFO, "Resource tables generated: " + clock.time(), true ); } catch ( RuntimeException ex ) { notifier.notify( jobId, ERROR, "Process failed: " + ex.getMessage(), true ); messageService.sendSystemErrorNotification( "Resource table process failed", ex ); throw ex; } }
/** * Set status properties of job after finish. If the job was executed manually and the job is disabled we want * to set the status back to DISABLED. * * @param clock Clock for keeping track of time usage * @param schedulingManager reference to scheduling manager * @param jobConfiguration the job configuration */ private void setFinishingStatus( Clock clock, SchedulingManager schedulingManager, JobConfiguration jobConfiguration ) { if ( jobConfiguration.isInMemoryJob() ) { return; } if ( !jobConfiguration.isContinuousExecution() ) { jobConfiguration.setJobStatus( JobStatus.SCHEDULED ); } if ( !jobConfiguration.isEnabled() ) { jobConfiguration.setJobStatus( JobStatus.DISABLED ); } jobConfiguration.setNextExecutionTime( null ); jobConfiguration.setLastExecuted( new Date() ); jobConfiguration.setLastRuntimeExecution( clock.time() ); schedulingManager.jobConfigurationFinished( jobConfiguration ); }
@Transactional @Override public void sendScheduledNotifications() { Clock clock = new Clock( log ).startClock() .logTime( "Processing ProgramStageNotification messages scheduled by program rules" ); List<ProgramNotificationInstance> templates = identifiableObjectManager.getAll( ProgramNotificationInstance.class ).stream() .filter( IS_SCHEDULED_BY_PROGRAM_RULE ).collect( Collectors.toList() ); if ( templates.isEmpty() ) { return; } int totalMessageCount = 0; List<MessageBatch> batches = templates.stream().filter( ProgramNotificationInstance::hasProgramInstance ) .map( t -> createProgramInstanceMessageBatch( t.getProgramNotificationTemplate(), Arrays.asList( t.getProgramInstance() ) ) ) .collect( Collectors.toList() ); batches.addAll( templates.stream().filter( ProgramNotificationInstance::hasProgramStageInstance ) .map( t -> createProgramStageInstanceMessageBatch( t.getProgramNotificationTemplate(), Arrays.asList( t.getProgramStageInstance() ) ) ) .collect( Collectors.toList() ) ); batches.stream().forEach( this::sendAll ); totalMessageCount = batches.stream().mapToInt( MessageBatch::messageCount ).sum(); clock.logTime( String.format( "Created and sent %d messages in %s", totalMessageCount, clock.time() ) ); }
Clock clock = new Clock( log ) .startClock() .logTime( String.format( "Starting update: %s, processes: %d, org unit levels: %d", tableType.getTableName(), processNo, orgUnitLevelNo ) ); clock.logTime( "Table updated aborted, no table or partitions found" ); notifier.notify( jobId, "Table updated aborted, no table or partitions found" ); return; clock.logTime( "Table update start: " + tableType.getTableName() + ", earliest: " + earliest + ", parameters: " + params.toString() ); notifier.notify( jobId, "Performing pre-create table work, org unit levels: " + orgUnitLevelNo ); clock.logTime( "Performed pre-create table work" ); notifier.notify( jobId, "Dropping temp tables" ); clock.logTime( "Dropped temp tables" ); notifier.notify( jobId, "Creating analytics tables" ); clock.logTime( "Created analytics tables" ); notifier.notify( jobId, "Populating analytics tables" ); clock.logTime( "Populated analytics tables" ); notifier.notify( jobId, "Invoking analytics table hooks" ); clock.logTime( "Invoked analytics table hooks" ); notifier.notify( jobId, "Applying aggregation levels" ); clock.logTime( "Applied aggregation levels" ); clock.logTime( "Tables vacuumed" );
final Clock clock = new Clock( log ).startClock().logTime( "Starting DataValueSynchronization job" ); final Date lastSuccessTime = getLastDataSynchSuccessFallback(); final int objectsToSynchronize = dataValueService.getDataValueCountLastUpdatedAfter( lastSuccessTime, true ); clock.logTime( "SUCCESS! DataValueSynchronization job is done. It took" ); setLastDataValueSynchronizationSuccess( new Date( clock.getStartTime() ) ); return SynchronizationResult.newSuccessResultWithMessage( "DataValueSynchronization done. It took " + clock.getTime() + " ms." );
@Override public void execute( JobConfiguration jobConfiguration ) throws Exception { final Clock clock = new Clock().startClock(); notifier.notify( jobConfiguration, "Sending scheduled dataset notifications" ); try { send(); notifier.notify( jobConfiguration, NotificationLevel.INFO, "Sent scheduled dataset notifications: " + clock.time(), true ); } catch ( RuntimeException ex ) { notifier.notify( jobConfiguration, NotificationLevel.ERROR, "Process failed: " + ex.getMessage(), true ); messageService.sendSystemErrorNotification( "Scheduled dataset notifications failed", ex ); throw ex; } }
@Override public void generateTables( AnalyticsTableUpdateParams params ) final Clock clock = new Clock( log ).startClock(); final JobConfiguration jobId = params.getJobId(); final Set<AnalyticsTableType> skipTypes = CollectionUtils.emptyIfNull( params.getSkipTableTypes() ); clock.logTime( "Analytics tables updated" ); notifier.notify( jobId, INFO, "Analytics tables updated: " + clock.time(), true ); systemSettingManager.saveSystemSetting( SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_RUNTIME, DateUtils.getPrettyInterval( clock.getSplitTime() ) );
private ImportSummary saveCompleteDataSetRegistrations( ImportOptions importOptions, JobConfiguration id, CompleteDataSetRegistrations completeRegistrations ) Clock clock = new Clock( log ).startClock() .logTime( "Starting complete data set registration import, options: " + importOptions ); notifier.clear( id ).notify( id, "Process started" ); clock.logTime( String.format( "Complete data set registration import done, total: %d, imported: %d, updated: %d, deleted: %d", totalCount, count.getImported(), count.getUpdated(), count.getDeleted() ) );
final Clock clock = new Clock( log ).startClock().logTime( "Starting anonymous event program data synchronization job." ); final int objectsToSynchronize = eventService.getAnonymousEventReadyForSynchronizationCount(); .collect( Collectors.toList() ); log.info( "The lastSynchronized flag of these Events will be updated: " + eventsUIDs ); eventService.updateEventsSyncTimestamp( eventsUIDs, new Date( clock.getStartTime() ) ); clock.logTime( "SUCCESS! Events sync was successfully done! It took " ); return SynchronizationResult.newSuccessResultWithMessage( "Events synchronization done. It took " + clock.getTime() + " ms." );
@Override public void execute( JobConfiguration jobConfiguration ) { final Clock clock = new Clock().startClock(); notifier.notify( jobConfiguration, "Sending new validation result notifications" ); try { runInternal(); notifier.notify( jobConfiguration, NotificationLevel.INFO, "Sent validation result notifications: " + clock.time(), true ); } catch ( RuntimeException ex ) { notifier.notify( jobConfiguration, NotificationLevel.ERROR, "Process failed: " + ex.getMessage(), true ); messageService .sendSystemErrorNotification( "Sending validation result notifications failed", ex ); throw ex; } }
Clock clock = new Clock( log ).startClock(); notifier.notify( jobId, NotificationLevel.INFO, "Import done. Completed in " + clock.time() + ".", true ). addJobSummary( jobId, importSummaries, ImportSummaries.class ); clock.logTime( "Import done" );
Clock clock = new Clock( log ).startClock().logTime( "Starting data value import, options: " + importOptions ); NotificationLevel notificationLevel = importOptions.getNotificationLevel( INFO ); notifier.clear( id ).notify( id, notificationLevel, "Process started" ); clock.logTime( "Validated outer meta-data" ); notifier.notify( id, notificationLevel, "Importing data values" ); summary.setDescription( "Import process completed successfully" ); clock.logTime( "Data value import done, total: " + totalCount + ", import: " + importCount + ", update: " + updateCount + ", delete: " + deleteCount ); notifier.notify( id, notificationLevel, "Import done", true ).addJobSummary( id, notificationLevel, summary, ImportSummary.class );