Search in sources :

Example 1 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project NabAlive by jcheype.

the class ApplicationScheduler method clock.

@Scheduled(cron = "0 0 * * * *")
public void clock() {
    logger.debug("clock trigger");
    // clock
    Application application = checkNotNull(applicationManager.getApplication(CLOCK_APIKEY));
    Query<Nabaztag> query = nabaztagDAO.createQuery().filter("applicationConfigList.applicationStoreApikey", CLOCK_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.isAsleep()) {
            try {
                application.onStartup(nabaztag, findConfig(CLOCK_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 2 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project cas by apereo.

the class AbstractServicesManager method load.

/**
 * Load services that are provided by the DAO.
 */
@Scheduled(initialDelayString = "${cas.serviceRegistry.schedule.startDelay:20000}", fixedDelayString = "${cas.serviceRegistry.schedule.repeatInterval:60000}")
@Override
@PostConstruct
public void load() {
    LOGGER.debug("Loading services from [{}]", this.serviceRegistry);
    this.services = this.serviceRegistry.load().stream().collect(Collectors.toConcurrentMap(r -> {
        LOGGER.debug("Adding registered service [{}]", r.getServiceId());
        return r.getId();
    }, Function.identity(), (r, s) -> s == null ? r : s));
    loadInternal();
    publishEvent(new CasRegisteredServicesLoadedEvent(this, getAllServices()));
    evaluateExpiredServiceDefinitions();
    LOGGER.info("Loaded [{}] service(s) from [{}].", this.services.size(), this.serviceRegistry.getName());
}
Also used : CasRegisteredServicesLoadedEvent(org.apereo.cas.support.events.service.CasRegisteredServicesLoadedEvent) Scheduled(org.springframework.scheduling.annotation.Scheduled) PostConstruct(javax.annotation.PostConstruct)

Example 3 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project webapp by elimu-ai.

the class MailChimpScheduler method executeDataSync.

/**
 * Sync data registered for existing subscribers.
 */
// 20 past every hour
@Scheduled(cron = "00 20 * * * *")
public synchronized void executeDataSync() {
    logger.info("executeDataSync");
    if (EnvironmentContextLoaderListener.env != Environment.PROD) {
        return;
    }
    List<Contributor> contributors = contributorDao.readAll();
    logger.info("contributors.size(): " + contributors.size());
    for (Contributor contributor : contributors) {
        try {
            String memberInfo = MailChimpApiHelper.getMemberInfo(contributor.getEmail());
            if (StringUtils.isNotBlank(memberInfo)) {
                // Sync Contributor data with mailing list
                MailChimpApiHelper.updateTeams(contributor.getEmail(), contributor.getTeams());
            }
        } catch (IOException ex) {
            logger.error(null, ex);
            break;
        }
    }
    logger.info("executeDataSync complete");
}
Also used : Contributor(ai.elimu.model.Contributor) IOException(java.io.IOException) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 4 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project NabAlive by jcheype.

the class ApplicationScheduler method scheduled.

@Scheduled(cron = "0 * * * * *")
public void scheduled() {
    logger.debug("scheduled");
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);
    int day = cal.get(Calendar.DAY_OF_WEEK);
    String scheduleKey = String.format("%02d:%02d-%d", hour, minute, day);
    logger.debug("scheduleKey: {}", scheduleKey);
    Query<Nabaztag> queryWakeUp = nabaztagDAO.createQuery().filter("wakeup", scheduleKey);
    sendToAll(queryWakeUp, new SleepPacket(SleepPacket.Action.WakeUp));
    Query<Nabaztag> querySleep = nabaztagDAO.createQuery().filter("sleep", scheduleKey);
    sendToAll(querySleep, new SleepPacket(SleepPacket.Action.Sleep));
}
Also used : Nabaztag(com.nabalive.data.core.model.Nabaztag) SleepPacket(com.nabalive.server.jabber.packet.SleepPacket) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 5 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)120 Date (java.util.Date)33 IOException (java.io.IOException)15 HashMap (java.util.HashMap)13 User (io.github.jhipster.sample.domain.User)8 List (java.util.List)8 Map (java.util.Map)8 File (java.io.File)7 ArrayList (java.util.ArrayList)7 SimpleDateFormat (java.text.SimpleDateFormat)6 Instant (java.time.Instant)6 LocalDate (java.time.LocalDate)6 SysConfig (com.itrus.portal.db.SysConfig)5 InetAddress (java.net.InetAddress)5 UnknownHostException (java.net.UnknownHostException)5 Contributor (ai.elimu.model.Contributor)4 Nabaztag (com.nabalive.data.core.model.Nabaztag)4 StoryBook (ai.elimu.model.content.StoryBook)3 Word (ai.elimu.model.content.Word)3 Locale (ai.elimu.model.enums.Locale)3