Search in sources :

Example 51 with Scheduled

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.");
    }
}
Also used : Task(org.activiti.api.task.model.Task) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) LinkedHashMap(java.util.LinkedHashMap) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 52 with Scheduled

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);
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 53 with Scheduled

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);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 54 with Scheduled

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);
                }
            }
        }
    }
}
Also used : Status(com.nabalive.server.jabber.Status) Nabaztag(com.nabalive.data.core.model.Nabaztag) Application(com.nabalive.application.core.Application) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 55 with Scheduled

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);
                }
            }
        }
    }
}
Also used : Status(com.nabalive.server.jabber.Status) Nabaztag(com.nabalive.data.core.model.Nabaztag) Application(com.nabalive.application.core.Application) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

Scheduled (org.springframework.scheduling.annotation.Scheduled)140 Date (java.util.Date)38 IOException (java.io.IOException)17 HashMap (java.util.HashMap)15 ArrayList (java.util.ArrayList)12 File (java.io.File)9 List (java.util.List)9 User (io.github.jhipster.sample.domain.User)8 SimpleDateFormat (java.text.SimpleDateFormat)8 LocalDate (java.time.LocalDate)8 Map (java.util.Map)8 Word (ai.elimu.model.content.Word)6 Instant (java.time.Instant)6 SysConfig (com.itrus.portal.db.SysConfig)5 InetAddress (java.net.InetAddress)5 UnknownHostException (java.net.UnknownHostException)5 Contributor (ai.elimu.model.Contributor)4 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)4 Language (ai.elimu.model.v2.enums.Language)4 Nabaztag (com.nabalive.data.core.model.Nabaztag)4