Search in sources :

Example 61 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project spring-boot-starter-samples by vindell.

the class DisruptorConfig method send.

// 每1s执行1次
@Scheduled(fixedDelay = 1000)
public void send() throws Exception {
    DisruptorBindEvent event = new DisruptorBindEvent(this, "message " + Math.random());
    event.setEvent("Event-Output");
    event.setTag("TagA-Output");
    event.setKey("id-" + Math.random());
    disruptorTemplate.publishEvent(event);
}
Also used : DisruptorBindEvent(com.lmax.disruptor.spring.boot.event.DisruptorBindEvent) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 62 with Scheduled

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

the class LetterUsageCountScheduler method execute.

// At 06:15 every day
@Scheduled(cron = "00 15 06 * * *")
public synchronized void execute() {
    logger.info("execute");
    logger.info("Calculating usage count for Letters");
    Map<String, Integer> letterFrequencyMap = new HashMap<>();
    Language language = Language.valueOf(ConfigHelper.getProperty("content.language"));
    List<StoryBook> storyBooks = storyBookDao.readAllOrdered();
    logger.info("storyBooks.size(): " + storyBooks.size());
    for (StoryBook storyBook : storyBooks) {
        logger.info("storyBook.getTitle(): " + storyBook.getTitle());
        List<String> paragraphs = new ArrayList<>();
        List<StoryBookChapter> storyBookChapters = storyBookChapterDao.readAll(storyBook);
        for (StoryBookChapter storyBookChapter : storyBookChapters) {
            List<StoryBookParagraph> storyBookParagraphs = storyBookParagraphDao.readAll(storyBookChapter);
            for (StoryBookParagraph storyBookParagraph : storyBookParagraphs) {
                paragraphs.add(storyBookParagraph.getOriginalText());
            }
        }
        Map<String, Integer> letterFrequencyMapForBook = LetterFrequencyHelper.getLetterFrequency(paragraphs, language);
        letterFrequencyMapForBook.keySet().forEach(letterText -> letterFrequencyMap.put(letterText, letterFrequencyMap.getOrDefault(letterText, 0) + letterFrequencyMapForBook.get(letterText)));
    }
    logger.info("letterFrequencyMap: " + letterFrequencyMap);
    for (String letterText : letterFrequencyMap.keySet()) {
        Letter existingLetter = letterDao.readByText(letterText);
        if (existingLetter != null) {
            existingLetter.setUsageCount(letterFrequencyMap.get(letterText));
            letterDao.update(existingLetter);
        }
    }
    logger.info("execute complete");
}
Also used : StoryBookChapter(ai.elimu.model.content.StoryBookChapter) StoryBook(ai.elimu.model.content.StoryBook) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StoryBookParagraph(ai.elimu.model.content.StoryBookParagraph) Letter(ai.elimu.model.content.Letter) Language(ai.elimu.model.v2.enums.Language) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 63 with Scheduled

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

the class SoundUsageCountScheduler method execute.

// At 06:30 every day
@Scheduled(cron = "00 30 06 * * *")
public synchronized void execute() {
    logger.info("execute");
    logger.info("Calculating usage count of Sounds");
    // Long = Sound ID
    // Integer = Usage count
    Map<Long, Integer> soundFrequencyMap = new HashMap<>();
    // Summarize the usage count of each Word's Sounds based on the LetterSoundCorrespondence's
    // usage count (see LetterSoundCorrespondenceUsageCountScheduler).
    List<Word> words = wordDao.readAllOrdered();
    logger.info("words.size(): " + words.size());
    for (Word word : words) {
        for (LetterSoundCorrespondence letterSoundCorrespondence : word.getLetterSoundCorrespondences()) {
            for (Sound sound : letterSoundCorrespondence.getSounds()) {
                soundFrequencyMap.put(sound.getId(), soundFrequencyMap.getOrDefault(sound.getId(), 0) + letterSoundCorrespondence.getUsageCount());
            }
        }
    }
    // Update each Sound's usage count in the database
    for (Long soundId : soundFrequencyMap.keySet()) {
        Sound sound = soundDao.read(soundId);
        sound.setUsageCount(soundFrequencyMap.get(soundId));
        soundDao.update(sound);
    }
    logger.info("execute complete");
}
Also used : Word(ai.elimu.model.content.Word) HashMap(java.util.HashMap) Sound(ai.elimu.model.content.Sound) LetterSoundCorrespondence(ai.elimu.model.content.LetterSoundCorrespondence) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 64 with Scheduled

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

the class WordUsageCountScheduler method execute.

// At 06:00 every day
@Scheduled(cron = "00 00 06 * * *")
public synchronized void execute() {
    logger.info("execute");
    logger.info("Calculating usage count for Words");
    Map<String, Integer> wordFrequencyMap = new HashMap<>();
    Language language = Language.valueOf(ConfigHelper.getProperty("content.language"));
    List<StoryBook> storyBooks = storyBookDao.readAllOrdered();
    logger.info("storyBooks.size(): " + storyBooks.size());
    for (StoryBook storyBook : storyBooks) {
        logger.info("storyBook.getTitle(): " + storyBook.getTitle());
        List<String> paragraphs = new ArrayList<>();
        List<StoryBookChapter> storyBookChapters = storyBookChapterDao.readAll(storyBook);
        for (StoryBookChapter storyBookChapter : storyBookChapters) {
            List<StoryBookParagraph> storyBookParagraphs = storyBookParagraphDao.readAll(storyBookChapter);
            for (StoryBookParagraph storyBookParagraph : storyBookParagraphs) {
                paragraphs.add(storyBookParagraph.getOriginalText());
            }
        }
        Map<String, Integer> wordFrequencyMapForBook = WordFrequencyHelper.getWordFrequency(paragraphs, language);
        wordFrequencyMapForBook.keySet().forEach(word -> wordFrequencyMap.put(word, wordFrequencyMap.getOrDefault(word, 0) + wordFrequencyMapForBook.get(word)));
    }
    for (String key : wordFrequencyMap.keySet()) {
        String wordLowerCase = key.toLowerCase();
        logger.info("wordLowerCase: \"" + wordLowerCase + "\"");
        Word word = wordDao.readByText(wordLowerCase);
        if (word != null) {
            word.setUsageCount(wordFrequencyMap.get(wordLowerCase));
            wordDao.update(word);
        }
    }
    logger.info("execute complete");
}
Also used : StoryBookChapter(ai.elimu.model.content.StoryBookChapter) StoryBook(ai.elimu.model.content.StoryBook) Word(ai.elimu.model.content.Word) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StoryBookParagraph(ai.elimu.model.content.StoryBookParagraph) Language(ai.elimu.model.v2.enums.Language) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 65 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project summer by foxsugar.

the class ScheduledService method scheduled.

/**
 * 每天5点 定时删除游戏记录
 */
@Scheduled(cron = "0 0 5 ? * *")
public void scheduled() {
    if (SpringUtil.getBean(ServerConfig.class).getDeleteRecordTask() == 1) {
        logger.info("=====>>>>>定时任务 删除游戏记录  {}", System.currentTimeMillis());
        LocalDate date = LocalDate.now();
        date = date.minusDays(7);
        ZoneId zoneId = ZoneId.systemDefault();
        ZonedDateTime zdt = date.atStartOfDay(zoneId);
        Date d = Date.from(zdt.toInstant());
        gameRecordService.gameRecordDao.deleteAllByDateBefore(d);
        gameRecordService.replayDao.deleteAllByDateBefore(d);
    }
// if (SpringUtil.getBean(ServerConfig.class).getLoadAllUser() == 1) {
// LocalDate yestoday = LocalDate.now().minusDays(1);
// String ys = yestoday.toString();
// //            ys = LocalDate.now().toString();
// for(String uid : RedisManager.getUserRedisService().getAllUserId()){
// long userId = Long.valueOf(uid);
// UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
// if (userBean.getVip() > 1 && userBean.getReferee() != 0) {
// 
// Double lastDayRebate = rebateDetailService.rebateDetailDao.getRebateByDate(userId, ys);
// if (lastDayRebate != null) {
// 
// double re = lastDayRebate /10;
// 
// UserBean parent = RedisManager.getUserRedisService().getUserBean(userBean.getReferee());
// parent.getUserInfo().setAllRebate(parent.getUserInfo().getAllRebate() + re);
// RedisManager.getUserRedisService().updateUserBean(parent.getId(), parent);
// 
// //返利记录
// RebateDetail rebateDetail = new RebateDetail();
// rebateDetail.setNum(re);
// rebateDetail.setUserId(userBean.getId());
// rebateDetail.setAgentId(parent.getId());
// rebateDetail.setDate(new Date());
// rebateDetail.setType(1);
// 
// rebateDetailService.rebateDetailDao.save(rebateDetail);
// }
// }
// }
// //            rebateDetailService.rebateDetailDao.findAllByAgentId()
// 
// LocalDate localDate = LocalDate.now().minusDays(8);
// rebateDetailService.rebateDetailDao.deleteAllByDateBefore(DateUtil.convertDay2Date(localDate.toString()));
// }
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) 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