use of org.springframework.scheduling.annotation.Scheduled in project Activiti by Activiti.
the class DemoApplication method checkAndWorkOnTasksWhenAvailable.
@Scheduled(initialDelay = 1000, fixedDelay = 5000)
public void checkAndWorkOnTasksWhenAvailable() {
securityUtil.logInAs("bob");
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 10));
if (tasks.getTotalItems() > 0) {
for (Task t : tasks.getContent()) {
logger.info("> Claiming task: " + t.getId());
taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(t.getId()).build());
List<VariableInstance> variables = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(t.getId()).build());
VariableInstance variableInstance = variables.get(0);
if (variableInstance.getName().equals("content")) {
LinkedHashMap contentToProcess = objectMapper.convertValue(variableInstance.getValue(), LinkedHashMap.class);
logger.info("> Content received inside the task to approve: " + contentToProcess);
if (contentToProcess.get("body").toString().contains("activiti")) {
logger.info("> User Approving content");
contentToProcess.put("approved", true);
} else {
logger.info("> User Discarding content");
contentToProcess.put("approved", false);
}
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(t.getId()).withVariable("content", contentToProcess).build());
}
}
} else {
logger.info("> There are no task for me to work on.");
}
}
use of org.springframework.scheduling.annotation.Scheduled in project Activiti by Activiti.
the class DemoApplication method processText.
@Scheduled(initialDelay = 1000, fixedDelay = 1000)
public void processText() {
securityUtil.logInAs("system");
String content = pickRandomString();
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yy HH:mm:ss");
logger.info("> Processing content: " + content + " at " + formatter.format(new Date()));
ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey("categorizeProcess").withName("Processing Content: " + content).withVariable("content", content).build());
logger.info(">>> Created Process Instance: " + processInstance);
}
use of org.springframework.scheduling.annotation.Scheduled in project SpringStepByStep by JavaProgrammerLB.
the class MyBean method printMessage.
@Scheduled(fixedRate = 1000)
public void printMessage() {
System.out.println("I am called by Spring scheduler");
Date date = new Date();
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String now = fmt.format(date);
System.out.println(now);
}
use of org.springframework.scheduling.annotation.Scheduled in project NabAlive by jcheype.
the class ApplicationScheduler method taichi.
@Scheduled(fixedDelay = 400000)
public void taichi() {
logger.debug("taichi trigger");
// taichi
Application application = checkNotNull(applicationManager.getApplication(TAICHI_APIKEY));
Query<Nabaztag> query = nabaztagDAO.createQuery().filter("applicationConfigList.applicationStoreApikey", TAICHI_APIKEY);
Iterator<Nabaztag> iterator = nabaztagDAO.find(query).iterator();
while (iterator.hasNext()) {
Nabaztag nabaztag = iterator.next();
Status status = connectionManager.get(nabaztag.getMacAddress());
if (status != null && status.isIdle()) {
if (rand.nextInt(4) == 0) {
try {
application.onStartup(nabaztag, findConfig(TAICHI_APIKEY, nabaztag.getApplicationConfigList()));
} catch (Exception e) {
logger.debug("cannot send message", e);
}
}
}
}
}
use of org.springframework.scheduling.annotation.Scheduled in project NabAlive by jcheype.
the class ApplicationScheduler method mood.
@Scheduled(fixedDelay = 300000)
public void mood() {
logger.debug("mood trigger");
// mood
Application application = checkNotNull(applicationManager.getApplication(MOOD_APIKEY));
Query<Nabaztag> query = nabaztagDAO.createQuery().filter("applicationConfigList.applicationStoreApikey", MOOD_APIKEY);
Iterator<Nabaztag> iterator = nabaztagDAO.find(query).iterator();
while (iterator.hasNext()) {
Nabaztag nabaztag = iterator.next();
Status status = connectionManager.get(nabaztag.getMacAddress());
if (status != null && status.isIdle()) {
if (rand.nextInt(4) == 0) {
try {
application.onStartup(nabaztag, findConfig(MOOD_APIKEY, nabaztag.getApplicationConfigList()));
} catch (Exception e) {
logger.debug("cannot send message", e);
}
}
}
}
}
Aggregations