1 | |
---|
2 | class TaskRecurringScheduleJob { |
---|
3 | def timeout = 5000 // execute job once in 5 seconds |
---|
4 | |
---|
5 | def execute() { |
---|
6 | println "5" |
---|
7 | def recurringScheduleInstanceList = RecurringSchedule.list() |
---|
8 | def now = new Date() |
---|
9 | |
---|
10 | recurringScheduleInstanceList.each() { |
---|
11 | |
---|
12 | if ( now < it.nextDueDate) { |
---|
13 | def taskInstance = it.task |
---|
14 | def subTaskInstance = new Task() |
---|
15 | |
---|
16 | //Make our new Task a subTask. |
---|
17 | subTaskInstance.parentTask = taskInstance |
---|
18 | |
---|
19 | // Set the required properties |
---|
20 | subTaskInstance.description = "Generated recurring task: "+taskInstance.description |
---|
21 | subTaskInstance.comment = taskInstance.comment |
---|
22 | subTaskInstance.taskGroup = taskInstance.taskGroup |
---|
23 | subTaskInstance.taskStatus = TaskStatus.findByName("Not Started") |
---|
24 | subTaskInstance.taskPriority = TaskPriority.get(2) |
---|
25 | subTaskInstance.taskType = TaskType.get(1) |
---|
26 | subTaskInstance.leadPerson = taskInstance.leadPerson |
---|
27 | if(subTaskInstance.save()){println "yes"} |
---|
28 | |
---|
29 | //Set the assignedPersons |
---|
30 | taskInstance.assignedPersons.each() { |
---|
31 | |
---|
32 | def assignedPerson = new AssignedPerson(person: it.person, |
---|
33 | task: subTaskInstance, |
---|
34 | estimatedHour: it.estimatedHour, |
---|
35 | estimatedMinute: it.estimatedMinute).save() |
---|
36 | } |
---|
37 | |
---|
38 | //Set the nextDueDate so that we don't loop ;-) |
---|
39 | // it.nextDueDate = new DateTime(date:2.weeks.from.now) |
---|
40 | |
---|
41 | } |
---|
42 | }//recurringScheduleInstanceList.each() |
---|
43 | } |
---|
44 | } |
---|