Index: trunk/grails-app/jobs/TaskRecurringScheduleJob.groovy
===================================================================
--- trunk/grails-app/jobs/TaskRecurringScheduleJob.groovy	(revision 137)
+++ trunk/grails-app/jobs/TaskRecurringScheduleJob.groovy	(revision 199)
@@ -1,47 +1,34 @@
+import org.codehaus.groovy.grails.commons.*
 
-class TaskRecurringScheduleJob {/*
-    def timeout = 1000 // execute job once in 1 seconds
-//     def timeout = 60000
+/**
+* Provides a quartz job that reviews and generates all recurring tasks.
+* The quartz scheduler is restarted if this file is edited so startDelay will then delay again.
+* The execute method is called once every repeatInterval (in milliseconds).
+* With concurrent=false the repeat interval starts counting after the previous job completes.
+* Apparently we need a hibernate session otherwise we get a LazyInitializationException, default is true but we specify it to be sure.
+*/
+class TaskRecurringScheduleJob {
+
+    def taskRecurringScheduleService
+
+    def concurrent = false
+    def sessionRequired = true
+
+    static triggers = {
+        simple name: "GenerateAll",
+                    startDelay: 60000,
+                    repeatInterval: ConfigurationHolder.config.taskRecurringScheduleJob.repeatInterval*1000
+    }
 
     def execute() {
-        println "TaskRecurringScheduleJob: tick"
-        println "TaskRecurringScheduleJob: tock"/*
-        def recurringScheduleInstanceList = RecurringSchedule.list()
-        def now = new Date()
 
-        recurringScheduleInstanceList.each() {
+        // Some information can be accessed if we run with "def execute(context) ".
+        // For more info see: http://quartz.sourceforge.net/javadoc/org/quartz/JobExecutionContext.html
+        // log.debug context.getTrigger()
+        // log.debug context.getPreviousFireTime()
+        // log.debug context.getFireTime()
 
-            if ( now > it.nextDueDate) {
-                def taskInstance = it.task
-                def subTaskInstance = new Task()
-    
-                //Make our new Task a subTask.
-                subTaskInstance.parentTask = taskInstance
-    
-                // Set the required properties
-                subTaskInstance.description = "Generated recurring task: "+taskInstance.description
-                subTaskInstance.comment = taskInstance.comment
-                subTaskInstance.taskGroup = taskInstance.taskGroup
-                subTaskInstance.taskStatus = TaskStatus.findByName("Not Started")
-                subTaskInstance.taskPriority = TaskPriority.get(2)
-                subTaskInstance.taskType = TaskType.get(1)
-                subTaskInstance.leadPerson = taskInstance.leadPerson
-                subTaskInstance.save()
-//                 if(subTaskInstance.save()){println "yes"}
-    
-                //Set the assignedPersons
-                taskInstance.assignedPersons.each() {
-    
-                def assignedPerson = new AssignedPerson(person: it.person,
-                                                                                        task: subTaskInstance,
-                                                                                        estimatedHour: it.estimatedHour,
-                                                                                        estimatedMinute: it.estimatedMinute).save()
-                }
-
-                //Set the nextDueDate so that we don't loop ;-)
-                it.nextDueDate = it.nextDueDate + 1
-    
-            }
-        }//recurringScheduleInstanceList.each()
-    }*/
+        // We do everything via services, quartz just sets up and fires off the thread.
+        taskRecurringScheduleService.generateAll()
+    }
 }
