Search in sources :

Example 71 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project CzechIdMng by bcvsolutions.

the class DefaultAttachmentManager method purgeTempFiles.

/**
 * Purge old temporary files once per day.
 * Temporary files older than configured ttl will be purged.
 *
 * @return purged files count
 */
@Scheduled(fixedDelay = 3600000)
public void purgeTempFiles() {
    int purgedFiles = 0;
    long ttl = attachmentConfiguration.getTempTtl();
    if (ttl == 0) {
        LOG.warn("Removing old temporary files is disabled. Configure property [{}] - time to live in milliseconds (greater than zero).", AttachmentConfiguration.PROPERTY_TEMP_TTL);
        return;
    }
    // 
    // purge older temporary files than purge time
    long purgeTime = System.currentTimeMillis() - ttl;
    File temp = new File(getTempPath());
    if (temp.isDirectory()) {
        File[] files = temp.listFiles();
        if (files != null) {
            for (File f : files) {
                try {
                    if (f.getName().endsWith("." + DEFAULT_TEMP_FILE_EXTENSION) && f.lastModified() < purgeTime) {
                        f.delete();
                        purgedFiles++;
                    }
                } catch (Exception ex) {
                    LOG.error("Removing old temporary [.{}] file [{}] failed", DEFAULT_TEMP_FILE_EXTENSION, f.getName(), ex);
                }
            }
        }
    }
    LOG.debug("Temporary files were purged [{}]", purgedFiles);
}
Also used : File(java.io.File) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 72 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManager method scheduleProcessCreated.

/**
 * Spring schedule new task after previous task ended (don't run concurrently)
 */
@Scheduled(fixedDelayString = "${" + SchedulerConfiguration.PROPERTY_EVENT_QUEUE_PROCESS + ":" + SchedulerConfiguration.DEFAULT_EVENT_QUEUE_PROCESS + "}")
public void scheduleProcessCreated() {
    if (!eventConfiguration.isAsynchronous()) {
        // prevent to debug some messages into log - usable for devs
        return;
    }
    // run as system - called from scheduler internally
    securityService.setSystemAuthentication();
    // 
    // calculate events to process
    String instanceId = configurationService.getInstanceId();
    List<IdmEntityEventDto> events = getCreatedEvents(instanceId);
    LOG.trace("Events to process [{}] on instance [{}].", events.size(), instanceId);
    for (IdmEntityEventDto event : events) {
        // @Transactional
        context.getBean(this.getClass()).executeEvent(event);
        ;
    }
}
Also used : IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 73 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project vft-capture by videofirst.

the class DefaultUploadService method purgeFinishedUploads.

@Scheduled(fixedDelayString = "${vft_config.upload.purgeFinishedUploadSchedule:2000}")
public void purgeFinishedUploads() {
    for (String captureId : uploads.keySet()) {
        Capture capture = uploads.get(captureId);
        LocalDateTime time = LocalDateTime.now().minusSeconds(uploadConfig.getKeepFinishedUploadsInSecs());
        if (capture.getUpload() != null && capture.getUpload().getState() == UploadState.finished && capture.getUpload().getFinished().isBefore(time)) {
            log.info("Removing capture " + captureId);
            uploads.remove(captureId);
        }
        log.debug("Not removing capture " + captureId);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) Capture(co.videofirst.vft.capture.model.capture.Capture) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 74 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project rocketmq-externals by apache.

the class DashboardCollectTask method collectTopic.

@Scheduled(cron = "30 0/1 * * * ?")
@MultiMQAdminCmdMethod(timeoutMillis = 5000)
public void collectTopic() {
    if (!rmqConfigure.isEnableDashBoardCollect()) {
        return;
    }
    Date date = new Date();
    Stopwatch stopwatch = Stopwatch.createStarted();
    try {
        TopicList topicList = mqAdminExt.fetchAllTopicList();
        Set<String> topicSet = topicList.getTopicList();
        for (String topic : topicSet) {
            if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) {
                continue;
            }
            TopicRouteData topicRouteData = mqAdminExt.examineTopicRouteInfo(topic);
            GroupList groupList = mqAdminExt.queryTopicConsumeByWho(topic);
            double inTPS = 0;
            long inMsgCntToday = 0;
            double outTPS = 0;
            long outMsgCntToday = 0;
            for (BrokerData bd : topicRouteData.getBrokerDatas()) {
                String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
                if (masterAddr != null) {
                    try {
                        stopwatch.start();
                        log.info("start time: {}", stopwatch.toString());
                        BrokerStatsData bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.TOPIC_PUT_NUMS, topic);
                        stopwatch.stop();
                        log.info("stop time : {}", stopwatch.toString());
                        stopwatch.reset();
                        inTPS += bsd.getStatsMinute().getTps();
                        inMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd);
                    } catch (Exception e) {
                    // throw Throwables.propagate(e);
                    }
                }
            }
            if (groupList != null && !groupList.getGroupList().isEmpty()) {
                for (String group : groupList.getGroupList()) {
                    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
                        String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
                        if (masterAddr != null) {
                            try {
                                String statsKey = String.format("%s@%s", topic, group);
                                BrokerStatsData bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.GROUP_GET_NUMS, statsKey);
                                outTPS += bsd.getStatsMinute().getTps();
                                outMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd);
                            } catch (Exception e) {
                            // throw Throwables.propagate(e);
                            }
                        }
                    }
                }
            }
            List<String> list;
            try {
                list = dashboardCollectService.getTopicMap().get(topic);
            } catch (ExecutionException e) {
                throw Throwables.propagate(e);
            }
            if (null == list) {
                list = Lists.newArrayList();
            }
            list.add(date.getTime() + "," + new BigDecimal(inTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + inMsgCntToday + "," + new BigDecimal(outTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + outMsgCntToday);
            dashboardCollectService.getTopicMap().put(topic, list);
        }
        log.debug("Topic Collected Data in memory = {}" + JsonUtil.obj2String(dashboardCollectService.getTopicMap().asMap()));
    } catch (Exception err) {
        throw Throwables.propagate(err);
    }
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Stopwatch(com.google.common.base.Stopwatch) Date(java.util.Date) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) BigDecimal(java.math.BigDecimal) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) ExecutionException(java.util.concurrent.ExecutionException) BrokerStatsData(org.apache.rocketmq.common.protocol.body.BrokerStatsData) Scheduled(org.springframework.scheduling.annotation.Scheduled) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Example 75 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project nixmash-blog by mintster.

the class GithubJobRunner method runGithubJob.

@Scheduled(fixedRateString = "${github.job.fixed.delay.seconds:60}000")
public void runGithubJob() {
    SimpleDateFormat format = new SimpleDateFormat("M-dd-yy hh:mm:ss");
    String startDateTime = format.format(new Date());
    JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis()).toJobParameters();
    try {
        logger.info("");
        logger.info("STARTING GITHUB BATCH JOB : " + startDateTime);
        JobExecution execution = jobLauncher.run(githubJob, jobParameters);
        logger.info("JOB STATUS  : " + execution.getStatus());
    } catch (Exception e) {
        e.printStackTrace();
        logger.info("JOB FAILED!!!");
    }
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobParametersBuilder(org.springframework.batch.core.JobParametersBuilder) JobParameters(org.springframework.batch.core.JobParameters) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) 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