package jobs;
import play.jobs.*;
import models.*;
import java.util.*;
import calculator.*;
import play.*;
@On("0 0 12 * * ?")
public class UpdateCounters extends Job {
public void doJob() {
List<Employee> empList = Employee.find("long and boring
SQL :)").fetch();
if (empList.isEmpty() != true) {
Iterator<Employee> empIterator = empList.iterator();
while (empIterator.hasNext()) {
Employee emp = empIterator.next();
CounterCalculator cc = new CounterCalculator(); //
magic stuff :) from calculator package
String[] calculations = cc.search(emp.id);
if (!calculations[0].isEmpty() && !calculations
[0].isEmpty()) {
emp.counter = calculations[0];
emp.treshold = calculations[1];
emp.save(); // no changes to the database
until UpdateCounders job finishes
}
}
}
}
}
There is something bad with this transaction ?
> --
>
> You received this message because you are subscribed to the Google
> Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en
> .
>
>
Something like:
@On("0 0 12 * * ?")
public class UpdateCounters extends Job {
public void doJob() {
List<Employee> empList = Employee.find("long and boring
SQL :)").fetch();
for(Employee emp : empList) {
new UpdateEmployeeJob(emp).now().get();
}
}
}
This way each UpdateEmployeeJob will have its own transaction;
I have a background job which will never stop (running in an endless
loop), thus the objects will never be commited when I call .save();