use of com.haulmont.cuba.core.entity.ScheduledTask in project cuba by cuba-platform.
the class Scheduling method processScheduledTasks.
@Override
public void processScheduledTasks(boolean onlyIfActive) {
if (onlyIfActive && !isActive())
return;
log.debug("Processing scheduled tasks");
if (schedulingStartTime == 0)
schedulingStartTime = timeSource.currentTimeMillis();
authentication.begin();
try {
StopWatch sw = new Slf4JStopWatch("Scheduling.processTasks");
Coordinator.Context context = coordinator.begin();
try {
for (ScheduledTask task : context.getTasks()) {
processTask(task);
}
} finally {
coordinator.end(context);
}
sw.stop();
} finally {
authentication.end();
}
}
use of com.haulmont.cuba.core.entity.ScheduledTask in project cuba by cuba-platform.
the class SchedulingServiceBean method setActive.
@Override
public void setActive(Set<ScheduledTask> tasks, boolean active) {
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
for (ScheduledTask task : tasks) {
ScheduledTask t = em.find(ScheduledTask.class, task.getId());
t.setActive(active);
}
tx.commit();
}
}
use of com.haulmont.cuba.core.entity.ScheduledTask in project cuba by cuba-platform.
the class SchedulingServiceBean method setActive.
@Override
public void setActive(ScheduledTask task, boolean active) {
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
ScheduledTask t = em.find(ScheduledTask.class, task.getId());
t.setActive(active);
tx.commit();
} finally {
tx.end();
}
}
use of com.haulmont.cuba.core.entity.ScheduledTask in project cuba by cuba-platform.
the class PersistenceAttributeLoadedCheckTest method setUp.
@Before
public void setUp() throws Exception {
dataManager = AppBeans.get(DataManager.class);
persistence = AppBeans.get(Persistence.class);
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
ScheduledTask task = new ScheduledTask();
task.setBeanName("BeanName");
task.setMethodName("MethodName");
taskId = task.getId();
User user = new User();
userId = user.getId();
user.setName("testUser");
user.setLogin("login" + userId);
user.setPassword("000");
user.setGroup(em.find(Group.class, groupId));
em.persist(user);
em.persist(task);
em.persist(user);
tx.commit();
}
taskView = new View(ScheduledTask.class, true).addProperty("beanName");
userView = new View(User.class, true).addProperty("login").addProperty("loginLowerCase").addProperty("name").addProperty("password").addProperty("group", new View(Group.class).addProperty("name")).addProperty("userRoles", new View(UserRole.class));
}
use of com.haulmont.cuba.core.entity.ScheduledTask in project cuba by cuba-platform.
the class SchedulingTest method testCurrentStart.
@Test
public void testCurrentStart() throws Exception {
Scheduling scheduling = new Scheduling() {
@Override
protected TimeZone getCurrentTimeZone() {
return TimeZone.getTimeZone("GMT-0");
}
};
ScheduledTask scheduledTask = new ScheduledTask();
scheduledTask.setSchedulingType(SchedulingType.CRON);
scheduledTask.setCron("*/5 * * * * *");
// scheduler has failed couple of runs and now we should run it
long currentStart = scheduling.calculateNextCronDate(scheduledTask, date("2013-11-13 15:29:00").getTime(), date("2013-11-13 15:30:00").getTime(), 10000l);
assertEquals(date("2013-11-13 15:29:55"), new Date(currentStart));
// last run was year ago, so now-frame should be considered
currentStart = scheduling.calculateNextCronDate(scheduledTask, date("2012-11-13 15:29:00").getTime(), date("2013-11-13 15:30:00").getTime(), 10000l);
assertEquals(date("2013-11-13 15:29:55"), new Date(currentStart));
// last run was very close to now, last start date should be considered
currentStart = scheduling.calculateNextCronDate(scheduledTask, date("2013-11-13 15:29:59").getTime(), date("2013-11-13 15:30:01").getTime(), 10000l);
assertEquals(date("2013-11-13 15:30:00"), new Date(currentStart));
scheduledTask.setCron("0 0 0 * * FRI");
// task should run in next friday
currentStart = scheduling.calculateNextCronDate(scheduledTask, date("2013-11-08 01:01:01").getTime(), date("2013-11-13 15:30:00").getTime(), 10000l);
assertEquals(date("2013-11-15 00:00:00"), new Date(currentStart));
currentStart = scheduling.calculateNextCronDate(scheduledTask, date("2013-11-08 01:01:01").getTime(), date("2013-11-08 01:01:02").getTime(), 600000l);
assertEquals(date("2013-11-15 00:00:00"), new Date(currentStart));
// task is late but matches frame
currentStart = scheduling.calculateNextCronDate(scheduledTask, date("2013-11-07 23:59:59").getTime(), date("2013-11-08 00:01:00").getTime(), 600000l);
assertEquals(date("2013-11-8 00:00:00"), new Date(currentStart));
// task is late and does not match frame
currentStart = scheduling.calculateNextCronDate(scheduledTask, date("2013-11-07 23:59:59").getTime(), date("2013-11-08 00:11:00").getTime(), 600000l);
assertEquals(date("2013-11-15 00:00:00"), new Date(currentStart));
scheduledTask.setCron("0 59 1 * * *");
// time shift forward
currentStart = scheduling.calculateNextCronDate(scheduledTask, date("2013-10-26 1:59:59").getTime(), date("2013-10-27 00:00:00").getTime(), 600000l);
assertEquals(date("2013-10-27 01:59:00"), new Date(currentStart));
// time shift backward
currentStart = scheduling.calculateNextCronDate(scheduledTask, date("2013-03-30 1:59:00").getTime(), date("2013-03-31 00:00:00").getTime(), 600000l);
assertEquals(date("2013-03-31 01:59:00"), new Date(currentStart));
}
Aggregations