Search in sources :

Example 96 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project hub-fortify-ssc-integration-service by blackducksoftware.

the class BlackDuckFortifyPhoneHomeJobConfig method execute.

/**
 * Schedule the job and add it to the job launcher
 *
 * @throws Exception
 */
// Run on same schedule as worker
@Scheduled(cron = "${cron.expressions}")
public void execute() throws Exception {
    JobParameters jobParams = new JobParametersBuilder().addString("JobID", String.valueOf(System.currentTimeMillis())).toJobParameters();
    jobLauncher.run(sendPhoneHomeDataJob(), jobParams);
}
Also used : JobParametersBuilder(org.springframework.batch.core.JobParametersBuilder) JobParameters(org.springframework.batch.core.JobParameters) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 97 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project mica2 by obiba.

the class TempFileService method cleanupTempFiles.

@Scheduled(fixedDelay = TEMP_FILE_CLEANUP_INTERVAL)
public void cleanupTempFiles() {
    log.debug("Cleaning up tempfiles");
    List<TempFile> tempFiles = tempFileRepository.findByCreatedDateLessThan(DateTime.now().minusHours(TEMP_FILE_EXPIRE_TIMEOUT), new PageRequest(0, 100));
    tempFiles.forEach(f -> tempFileRepository.delete(f));
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) TempFile(org.obiba.mica.file.TempFile) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 98 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project mica2 by obiba.

the class DocumentSetService method cleanupOldSets.

@Async
@Scheduled(cron = "${sets.cleanup.cron:0 0 * * * ?}")
public void cleanupOldSets() {
    MicaConfig config = micaConfigService.getConfig();
    documentSetRepository.findAll().forEach(set -> {
        int timeToLive = set.hasName() ? config.getSetTimeToLive() : config.getCartTimeToLive();
        DateTime deadline = DateTime.now().minusDays(timeToLive);
        if (set.getLastModifiedDate().isBefore(deadline) && !set.isLocked()) {
            log.debug("Last updated {} - expiration {}", set.getLastModifiedDate(), deadline);
            log.info("{} {} has expired, deleting...", (set.hasName() ? "Set" : "Cart"), set.getId());
            delete(set);
        }
    });
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) DateTime(org.joda.time.DateTime) Scheduled(org.springframework.scheduling.annotation.Scheduled) Async(org.springframework.scheduling.annotation.Async)

Example 99 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project mica2 by obiba.

the class DataAccessRequestReportNotificationService method remindDataAccessReports.

@Async
@Scheduled(cron = "${dar.reminder.cron:0 0 0 * * ?}")
public void remindDataAccessReports() {
    DataAccessConfig dataAccessConfig = dataAccessConfigService.getOrCreateConfig();
    if (!dataAccessConfig.isNotifyFinalReport() && !dataAccessConfig.isNotifyIntermediateReport())
        return;
    int nbOfDaysBeforeReport = dataAccessConfig.getNbOfDaysBeforeReport();
    if (nbOfDaysBeforeReport < 0)
        return;
    LocalDate dateNow = LocalDate.now().minusDays(nbOfDaysBeforeReport);
    for (DataAccessRequest dar : dataAccessRequestService.findByStatus(Lists.newArrayList(DataAccessEntityStatus.APPROVED.name()))) {
        DataAccessRequestTimeline timeline = getReportsTimeline(dar);
        if (timeline.hasEndDate()) {
            LocalDate localEndDate = toLocalDate(timeline.getEndDate());
            if (dataAccessConfig.isNotifyFinalReport() && dateNow.plusDays(nbOfDaysBeforeReport).equals(localEndDate)) {
                // today is the day to notify final report
                remindDataAccessFinalReport(dataAccessConfig, dar, timeline.getEndDate(), nbOfDaysBeforeReport);
            } else if (dataAccessConfig.isNotifyIntermediateReport() && timeline.hasIntermediateDates()) {
                for (Date interDate : timeline.getIntermediateDates()) {
                    if (dateNow.plusDays(nbOfDaysBeforeReport).equals(toLocalDate(interDate))) {
                        remindDataAccessIntermediateReport(dataAccessConfig, dar, interDate, nbOfDaysBeforeReport);
                        break;
                    }
                }
            }
        } else {
            log.warn("No end date found for data access request {}", dar.getId());
        }
    }
}
Also used : DataAccessConfig(org.obiba.mica.micaConfig.domain.DataAccessConfig) DataAccessRequestTimeline(org.obiba.mica.access.domain.DataAccessRequestTimeline) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) Scheduled(org.springframework.scheduling.annotation.Scheduled) Async(org.springframework.scheduling.annotation.Async)

Example 100 with Scheduled

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

the class LetterSoundCorrespondenceUsageCountScheduler 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 LetterSoundCorrespondences");
    // <id, usageCount>
    Map<Long, Integer> letterSoundCorrespondenceFrequencyMap = new HashMap<>();
    List<Word> words = wordDao.readAll();
    logger.info("words.size(): " + words.size());
    for (Word word : words) {
        logger.info("word.getText(): " + word.getText());
        for (LetterSoundCorrespondence letterSoundCorrespondence : word.getLetterSoundCorrespondences()) {
            letterSoundCorrespondenceFrequencyMap.put(letterSoundCorrespondence.getId(), letterSoundCorrespondenceFrequencyMap.getOrDefault(letterSoundCorrespondence.getId(), 0) + word.getUsageCount());
        }
    }
    // Update the values previously stored in the database
    for (LetterSoundCorrespondence letterSoundCorrespondence : letterSoundCorrespondenceDao.readAll()) {
        logger.info("letterSoundCorrespondence.getId(): " + letterSoundCorrespondence.getId());
        logger.info("letterSoundCorrespondence Letters: \"" + letterSoundCorrespondence.getLetters().stream().map(Letter::getText).collect(Collectors.joining()) + "\"");
        logger.info("letterSoundCorrespondence Sounds: /" + letterSoundCorrespondence.getSounds().stream().map(Sound::getValueIpa).collect(Collectors.joining()) + "/");
        logger.info("letterSoundCorrespondence.getUsageCount() (before update): " + letterSoundCorrespondence.getUsageCount());
        int newUsageCount = 0;
        if (letterSoundCorrespondenceFrequencyMap.containsKey(letterSoundCorrespondence.getId())) {
            newUsageCount = letterSoundCorrespondenceFrequencyMap.get(letterSoundCorrespondence.getId());
        }
        logger.info("newUsageCount: " + newUsageCount);
        letterSoundCorrespondence.setUsageCount(newUsageCount);
        letterSoundCorrespondenceDao.update(letterSoundCorrespondence);
        logger.info("letterSoundCorrespondence.getUsageCount() (after update): " + letterSoundCorrespondence.getUsageCount());
    }
    logger.info("execute complete");
}
Also used : Letter(ai.elimu.model.content.Letter) 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)

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