@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() ) ); }
/** * 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() ); } }
@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() ) ); }
log.info( "Analyzed resource table: " + resourceTable.getTableName() + ", done in: " + clock.time() );
@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; } }
@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; } }
@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 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; } }
notifier.notify( jobId, INFO, "Analytics tables updated: " + clock.time(), true );
/** * 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 ); }
notifier.notify( jobId, NotificationLevel.INFO, "Import done. Completed in " + clock.time() + ".", true ). addJobSummary( jobId, importSummaries, ImportSummaries.class );