> There was another hack by Paul Browne or Stephen Horgan or one of the
> other fine folks from IBM that fired off all batch jobs on startup,
> but I can't find it right now. It might have been posted on the
> mifos-developer mailing list some time ago.

Here's what I was thinking of:
http://www.mifos.org/developers/wiki/HowToRunBatchJobsOnStartup

I'm also attaching the patch for historical record. It is out of date
and may not work, but it may be helpful for someone hacking on batch
jobs.
# see http://mifos.org/developers/wiki/HowToRunBatchJobsOnStartup
Index: mifos/src/main/java/org/mifos/framework/components/batchjobs/MifosScheduler.java
===================================================================
--- mifos/src/main/java/org/mifos/framework/components/batchjobs/MifosScheduler.java	(revision 14339)
+++ mifos/src/main/java/org/mifos/framework/components/batchjobs/MifosScheduler.java	(working copy)
@@ -43,11 +43,13 @@
 import java.util.Date;
 import java.util.List;
 import java.util.Timer;
+import java.util.WeakHashMap;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.mifos.core.ClasspathResource;
+import org.mifos.framework.components.batchjobs.exceptions.BatchJobException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
@@ -59,6 +61,10 @@
 	
 	List<String> taskNames = new ArrayList<String>();
 
+	//The weak HashMap allows us to keep a handle to the schedule tasks within the Mifos program,
+	//but still allows Garbage collection within the task
+	WeakHashMap<String,MifosTask> scheduledTasks = new WeakHashMap<String,MifosTask>();
+	
 	public MifosScheduler() {
 		timer = new Timer();
 	}
@@ -70,6 +76,7 @@
 	public void schedule(MifosTask task, Date initial, long delay) {
 		timer.schedule(task, initial, delay);
 		taskNames.add(task.name);
+		scheduledTasks.put(task.name,task);
 	}
 
 	/**
@@ -126,6 +133,10 @@
 				schedule(mifosTask, parseInitialTime(initialTime));
 			}
 		}
+		
+		if(true){
+			runTasksOnStartup();
+		}
 	}
 
 	/**
@@ -138,6 +149,7 @@
 	public void schedule(MifosTask task, Date initial) {
 		timer.schedule(task, initial);
 		taskNames.add(task.name);
+		scheduledTasks.put(task.name,task);
 	}
 
 	/**
@@ -164,4 +176,31 @@
 		return taskNames;
 	}
 
+	/*
+	 * For Debugging purposes , allows us to run (normally scheduled) tasks on startup
+	 * 
+	 */
+	private void runTasksOnStartup(){
+		
+		Date now =Calendar.getInstance().getTime();
+		
+		System.out.println("MifosScheduler start runTasksOnStartup()");
+		System.out.println("System Time"+now);
+		
+		MifosTask task = null;
+		
+		 for (String taskName : scheduledTasks.keySet()){
+			 task = scheduledTasks.get(taskName);
+			 System.out.println("MifosScheduler Calling "+task+".execute");
+			 try{
+				 task.getTaskHelper().execute(0);
+				 System.out.println("MifosScheduler "+task+" completed");
+			 }catch (BatchJobException bje){
+				 System.out.println("MifosScheduler Exception in task "+task+"\n"+bje.getErrorMessage());
+			 }		 
+			 
+		 }
+		 System.out.println("MifosScheduler end runTasksOnStartup()");
+		
+	}
 }

Attachment: signature.asc
Description: This is a digitally signed message part

------------------------------------------------------------------------------
_______________________________________________
Mifos-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mifos-users

Reply via email to