← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21934: MessageScheduler Bug Fixed

 

------------------------------------------------------------
revno: 21934
committer: Zubair Asghar<rajazubair.asghar@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-02-10 15:57:19 +0100
message:
  MessageScheduler Bug Fixed
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/DefaultProgramSchedulingManager.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/SendScheduledMessageTask.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/resources/META-INF/dhis/beans.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2016-02-10 14:57:19 +0000
@@ -112,7 +112,7 @@
         sql += " UNION ( " + sendMessageToUsersSql() + " ) ";
 
         sql += " UNION ( " + sendMessageToUserGroupsSql() + " ) ";
-
+        
         SqlRowSet rs = jdbcTemplate.queryForRowSet( sql );
 
         Collection<SchedulingProgramObject> schedulingProgramObjects = new HashSet<>();
@@ -153,7 +153,7 @@
 
             SchedulingProgramObject schedulingProgramObject = new SchedulingProgramObject();
             schedulingProgramObject.setProgramStageInstanceId( programstageinstanceid );
-            schedulingProgramObject.setPhoneNumber( rs.getString( "phonenumber" ) );
+            schedulingProgramObject.setPhoneNumber( rs.getString( "PHONE_NUMBER" ) );
             schedulingProgramObject.setMessage( message );
 
             schedulingProgramObjects.add( schedulingProgramObject );
@@ -273,7 +273,7 @@
 
     private String sendMessageToTrackedEntityInstanceSql()
     {
-        return "select psi.programstageinstanceid, pav.value as phonenumber, prm.templatemessage, org.name as orgunitName "
+        return "select psi.programstageinstanceid, pav.value as PHONE_NUMBER, prm.templatemessage, org.name as orgunitName "
             + ",pg.name as programName, ps.name as programStageName, psi.duedate,(DATE(now()) - DATE(psi.duedate) ) as days_since_due_date "
             + "from trackedentityinstance p INNER JOIN programinstance pi "
             + "     ON p.trackedentityinstanceid=pi.trackedentityinstanceid "
@@ -295,7 +295,7 @@
             + EventStatus.ACTIVE.name()
             + "'     and prm.templatemessage is not NULL and prm.templatemessage != '' "
             + "     and pg.type='" + ProgramType.WITH_REGISTRATION.name() + "' and prm.daysallowedsendmessage is not null  "
-            + "     and psi.executiondate is null and pa.valuetype='phoneNumber' "
+            + "     and psi.executiondate is null and pa.valuetype='PHONE_NUMBER' "
             + "     and (  DATE(now()) - DATE(psi.duedate) ) = prm.daysallowedsendmessage "
             + "     and prm.whentosend is null and prm.sendto = " + TrackedEntityInstanceReminder.SEND_TO_TRACKED_ENTITY_INSTANCE;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/DefaultProgramSchedulingManager.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/DefaultProgramSchedulingManager.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/DefaultProgramSchedulingManager.java	2016-02-10 14:57:19 +0000
@@ -106,19 +106,14 @@
     }
     
     @Override
-    public void executeTasks()
+    public void executeTasks() 
     {
-        Map<String, String> keyCronMap = getScheduledTasks();
-        
-        for ( String key : keyCronMap.keySet() )
-        {
-            Runnable task = tasks.get( key );
-            
-            if ( task != null )
-            {
-                scheduler.executeTask( task );
-            }
-        }
+          Runnable task = tasks.get( "sendMessageScheduledNow" );
+          
+          if ( task != null )
+          {
+              scheduler.executeTask( task );
+          }
     }
     
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/SendScheduledMessageTask.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/SendScheduledMessageTask.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/SendScheduledMessageTask.java	2016-02-10 14:57:19 +0000
@@ -109,6 +109,13 @@
         this.sendingMessage = sendingMessage;
     }
 
+    private Boolean sendNow;
+
+    public void setSendNow( Boolean sendNow )
+    {
+        this.sendNow = sendNow;
+    }
+
     private TaskId taskId;
 
     public void setTaskId( TaskId taskId )
@@ -128,9 +135,31 @@
         Clock clock = new Clock().startClock().logTime(
             "Aggregate process started, number of CPU cores: " + cpuCores + ", " + SystemUtils.getMemoryString() );
 
+        if ( sendNow )
+        {
+            clock.logTime( "Starting to prepare reminder messages" );
+            notifier.clear( taskId ).notify( taskId, "Start to prepare reminder messages" );
+
+            scheduleProgramStageInstanceMessage();
+            scheduleProgramInstanceMessage();
+
+            clock.logTime( "Preparing reminder messages completed" );
+            notifier.notify( taskId, INFO, "Preparing reminder messages completed", true );
+
+            clock.logTime( "Starting to send messages in outbound" );
+            notifier.notify( taskId, INFO, "Start to send messages in outbound", true );
+
+            sendMessage();
+
+            clock.logTime( "Sending messages in outbound completed" );
+            notifier.notify( taskId, INFO, "Sending messages in outbound completed", true );
+            
+            return;
+        }
+
         if ( sendingMessage )
         {
-            clock.logTime( "Start to send messages in outbound" );
+            clock.logTime( "Starting to send messages in outbound" );
             notifier.notify( taskId, INFO, "Start to send messages in outbound", true );
 
             sendMessage();
@@ -140,12 +169,12 @@
         }
         else
         {
-            clock.logTime( "Start to prepare reminder messages" );
+            clock.logTime( "Starting to prepare reminder messages" );
             notifier.clear( taskId ).notify( taskId, "Start to prepare reminder messages" );
 
             scheduleProgramStageInstanceMessage();
             scheduleProgramInstanceMessage();
-            
+
             clock.logTime( "Preparing reminder messages completed" );
             notifier.notify( taskId, INFO, "Preparing reminder messages completed", true );
         }
@@ -185,13 +214,13 @@
 
                 String sql = "INSERT INTO programstageinstance_outboundsms"
                     + "( programstageinstanceid, outboundsmsid, sort_order) VALUES " + "("
-                    + schedulingProgramObject.getProgramStageInstanceId() + ", " + outboundSms.getId() + ","
-                    + sortOrder + ") ";
+                    + schedulingProgramObject.getProgramStageInstanceId() + ", " + outboundSms.getId() + "," + sortOrder
+                    + ") ";
 
                 jdbcTemplate.execute( sql );
 
-                notifier.notify( taskId, "Reminder messages for event of " + outboundSms.getRecipients()
-                    + " is created " );
+                notifier.notify( taskId,
+                    "Reminder messages for event of " + outboundSms.getRecipients() + " is created " );
             }
             catch ( SmsServiceException e )
             {
@@ -204,7 +233,7 @@
 
     private void scheduleProgramInstanceMessage()
     {
-        notifier.notify( taskId, "Start to prepare reminder messages for enrollements" );
+        notifier.notify( taskId, "Start to prepare remigetScheduledTasksnder messages for enrollements" );
 
         Collection<SchedulingProgramObject> schedulingProgramObjects = programInstanceService.getScheduledMessages();
 
@@ -234,8 +263,8 @@
 
                 jdbcTemplate.execute( sql );
 
-                notifier.notify( taskId, "Reminder messages for enrollement of " + outboundSms.getRecipients()
-                    + " is created " );
+                notifier.notify( taskId,
+                    "Reminder messages for enrollement of " + outboundSms.getRecipients() + " is created " );
             }
             catch ( SmsServiceException e )
             {

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/resources/META-INF/dhis/beans.xml	2015-12-05 10:23:42 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/resources/META-INF/dhis/beans.xml	2016-02-10 14:57:19 +0000
@@ -69,6 +69,7 @@
 			<map>
 				<entry key="scheduleMessage" value-ref="scheduleMessage" />
 				<entry key="sendMessageScheduled" value-ref="sendMessageScheduled" />
+				<entry key="sendMessageScheduledNow" value-ref="sendMessageScheduledNow" />
 			</map>
 		</property>
 	</bean>
@@ -89,12 +90,21 @@
 		class="org.hisp.dhis.scheduling.SendScheduledMessageTask"
 		parent="abstractScheduledMessageTask" scope="prototype">
 		<property name="sendingMessage" value="true" />
+		<property name="sendNow" value="false"/>
 	</bean>
 
 	<bean id="scheduleMessage"
 		class="org.hisp.dhis.scheduling.SendScheduledMessageTask"
 		parent="abstractScheduledMessageTask" scope="prototype">
 		<property name="sendingMessage" value="false" />
+		<property name="sendNow" value="false"/>
+	</bean>
+	
+	<bean id="sendMessageScheduledNow"
+		class="org.hisp.dhis.scheduling.SendScheduledMessageTask"
+		parent="abstractScheduledMessageTask" scope="prototype">
+		<property name="sendingMessage" value="false" />
+		<property name="sendNow" value="true"/>
 	</bean>
 	
 	<!-- DeletionManager -->