Search in sources :

Example 76 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project portal by ixinportal.

the class SendReNewInfoTask method sendReNewInfo.

/**
 * 心跳更新。启动时执行一次,之后每隔24小时执行一次
 */
@Scheduled(fixedRate = 1000 * 60 * 60 * 24)
public void sendReNewInfo() {
    // 筛选出所有是待更新的,而且未发送短信的订单
    BillExample billExample = new BillExample();
    BillExample.Criteria criteria = billExample.or();
    // 订单状态是12的时候,表示是待更新的订单
    criteria.andBillStatusEqualTo(ComNames.BILL_STATUS_12);
    // 订单的短信发送时间是Null的时候,表示未发送过通知短信
    criteria.andRenewSendTimeIsNull();
    criteria.andIsDeleteEqualTo(false);
    // billExample.setLimit(100);
    List<Bill> bills = sqlSession.selectList("com.itrus.portal.db.BillMapper.selectByExample", billExample);
    if (null == bills || bills.size() < 1) {
        return;
    }
    String billSn = "";
    String mPhone = "";
    try {
        // 向每个订单发送短信通知
        for (int i = 0; i < bills.size(); i++) {
            billSn = bills.get(i).getBillId();
            UserInfo userInfo = sqlSession.selectOne("com.itrus.portal.db.UserInfoMapper.selectByPrimaryKey", bills.get(i).getUniqueId());
            mPhone = userInfo.getmPhone();
            UserCertExample userCertExample = new UserCertExample();
            UserCertExample.Criteria ucriteria = userCertExample.or();
            ucriteria.andIdEqualTo(bills.get(i).getOldUserCert());
            UserCert userCert = sqlSession.selectOne("com.itrus.portal.db.UserCertMapper.selectByExample", userCertExample);
            Enterprise enterprise = sqlSession.selectOne("com.itrus.portal.db.EnterpriseMapper.selectByPrimaryKey", bills.get(i).getEnterprise());
            Long projectId = bills.get(i).getProject();
            String keySn = "";
            if (null == userCert.getKeySn()) {
                keySn = "该证书未绑定key";
            } else {
                keySn = userCert.getKeySn();
            }
            String enterpriseName = enterprise.getEnterpriseName();
            Date endTime = userCert.getCertEndTime();
            // 获取订单对应的产品信息
            Product product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", bills.get(i).getProduct());
            String productName = product.getName();
            try {
                makeCerServiceImpl.sendReNewInfo(bills.get(i), mPhone, projectId, "ZSGX", keySn, enterpriseName, endTime, productName);
            } catch (UserInfoServiceException e) {
                String type = "发送证书更新通知失败";
                String info = "用户手机号:" + mPhone + ",订单号" + bills.get(i).getBillId() + "错误信息:" + e.getMessage();
                LogUtil.syslog(sqlSession, type, info);
                log.error("ERRORLOG证书更新通知 {}", info);
                return;
            } catch (Exception e) {
                String type = "发送证书更新通知失败";
                String info = "用户手机号:" + mPhone + ",订单号" + bills.get(i).getBillId() + "错误信息:" + e.getMessage();
                LogUtil.syslog(sqlSession, type, info);
                log.error("ERRORLOG证书更新通知 {}", info);
                return;
            }
        }
    } catch (Exception e) {
        String type = "发送证书更新通知失败";
        String info = "用户手机号:" + mPhone + ",订单号" + billSn + "错误信息:" + e.getMessage();
        LogUtil.syslog(sqlSession, type, info);
        log.error("ERRORLOG证书更新通知 {}", info);
        return;
    }
}
Also used : UserCertExample(com.itrus.portal.db.UserCertExample) Product(com.itrus.portal.db.Product) UserInfo(com.itrus.portal.db.UserInfo) Date(java.util.Date) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) BillExample(com.itrus.portal.db.BillExample) Bill(com.itrus.portal.db.Bill) Enterprise(com.itrus.portal.db.Enterprise) UserCert(com.itrus.portal.db.UserCert) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 77 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project portal by ixinportal.

the class SendSMSSHJJTask method task.

@Scheduled(fixedRate = 1000 * 60 * 60 * 2)
public void task() {
    // start------------处理双机互斥----------
    if (null == taskFlag) {
        taskFlag = systemConfigService.isTimedTaskHost();
    }
    if (taskFlag.equals(false)) {
        return;
    }
    // end------------处理双机互斥----------
    BillExample billExample = new BillExample();
    BillExample.Criteria criteria = billExample.or();
    // 订单状态是15的时候,表示是解锁审核拒绝的订单
    criteria.andBillStatusEqualTo(ComNames.BILL_STATUS_15);
    // 订单的短信发送时间是Null的时候,表示未发送过通知短信
    criteria.andIsDeleteEqualTo(false);
    criteria.andIsSmsEqualTo(false);
    criteria.andSendTimeIsNull();
    billExample.setLimit(20);
    List<Bill> bills = sqlSession.selectList("com.itrus.portal.db.BillMapper.selectByExample", billExample);
    Integer successNumer = 0;
    for (Bill bill : bills) {
        try {
            if (reviewService.sendSmsBySHJJ(bill.getId())) {
                // 修改订单
                bill.setIsSms(true);
                bill.setSendTime(new Date());
                sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKey", bill);
                successNumer++;
            }
        } catch (Exception e) {
            LogUtil.syslog(sqlSession, "审核拒绝短信通知_解锁订单", "出现异常,异常信息:" + e.getMessage());
        }
    }
    LogUtil.syslog(sqlSession, "审核拒绝短信通知_解锁订单", "本次发送成功:" + successNumer + ",条, 总计:" + (null == bills ? 0 : bills.size()) + "条");
}
Also used : BillExample(com.itrus.portal.db.BillExample) Bill(com.itrus.portal.db.Bill) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 78 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project ORCID-Source by ORCID.

the class HandleFailedMessages method resendFailedElements.

@Scheduled(cron = "${org.orcid.cron.reindex-failed}")
public void resendFailedElements() {
    List<RecordStatusEntity> failedElements = manager.getFailedElements(BATCH_SIZE);
    List<RecordStatusEntity> elementsToNotify = new ArrayList<RecordStatusEntity>();
    for (RecordStatusEntity element : failedElements) {
        try {
            // Send RetryMessage for 1.2 dump
            if (element.getDumpStatus12Api() > 0) {
                RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.DUMP_STATUS_1_2_API.value());
                jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
            }
            // Send RetryMessage for 2.0 dump
            if (element.getDumpStatus20Api() > 0) {
                RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.DUMP_STATUS_2_0_API.value());
                jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
            }
            // Send RetryMessage for solr indexing
            if (element.getSolrStatus20Api() > 0) {
                RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.SOLR.value());
                jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
            }
            // Send RetryMessage for 2.0 activities dump
            if (element.getDumpStatus20ActivitiesApi() > 0) {
                RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.DUMP_STATUS_2_0_ACTIVITIES_API.value());
                jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
            }
            // Should we notify about this element?
            if ((element.getDumpStatus12Api() > maxFailuresBeforeNotify) || (element.getDumpStatus20Api() > maxFailuresBeforeNotify) || (element.getSolrStatus20Api() > maxFailuresBeforeNotify) || (element.getDumpStatus20ActivitiesApi() > maxFailuresBeforeNotify)) {
                elementsToNotify.add(element);
            }
        } catch (JmsException e) {
            LOGGER.warn("Unable to resend message for " + element.getId());
        }
    }
    // Send summary
    if (!elementsToNotify.isEmpty()) {
        String message = buildNotificationMessage(elementsToNotify);
        sendSystemAlert(message);
    }
}
Also used : RecordStatusEntity(org.orcid.listener.persistence.entities.RecordStatusEntity) JmsException(org.springframework.jms.JmsException) ArrayList(java.util.ArrayList) RetryMessage(org.orcid.utils.listener.RetryMessage) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 79 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project PublicCMS-preview by sanluan.

the class ScheduledTaskComponent method clearAppToken.

/**
 * 每分钟清理半小时前的token
 */
@Scheduled(fixedDelay = 60 * 1000L)
public void clearAppToken() {
    if (CmsVersion.isInitialized() && CmsVersion.isMaster()) {
        Date date = DateUtils.addMinutes(CommonUtils.getDate(), -30);
        appTokenService.delete(date);
        emailTokenService.delete(date);
    }
}
Also used : Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 80 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project spring-cloud-consul by spring-cloud.

the class ConfigWatch method watchConfigKeyValues.

@Scheduled(fixedDelayString = "${spring.cloud.consul.config.watch.delay:1000}")
@Timed(value = "consul.watch-config-keys")
public void watchConfigKeyValues() {
    if (this.running.get()) {
        for (String context : this.consulIndexes.keySet()) {
            // turn the context into a Consul folder path (unless our config format are FILES)
            if (properties.getFormat() != FILES && !context.endsWith("/")) {
                context = context + "/";
            }
            try {
                Long currentIndex = this.consulIndexes.get(context);
                if (currentIndex == null) {
                    currentIndex = -1L;
                }
                // use the consul ACL token if found
                String aclToken = properties.getAclToken();
                if (StringUtils.isEmpty(aclToken)) {
                    aclToken = null;
                }
                Response<List<GetValue>> response = this.consul.getKVValues(context, aclToken, new QueryParams(this.properties.getWatch().getWaitTime(), currentIndex));
                // reducing churn if there wasn't anything
                if (response.getValue() != null && !response.getValue().isEmpty()) {
                    Long newIndex = response.getConsulIndex();
                    if (newIndex != null && !newIndex.equals(currentIndex)) {
                        // don't publish the same index again, don't publish the first time (-1) so index can be primed
                        if (!this.consulIndexes.containsValue(newIndex) && !currentIndex.equals(-1L)) {
                            RefreshEventData data = new RefreshEventData(context, currentIndex, newIndex);
                            this.publisher.publishEvent(new RefreshEvent(this, data, data.toString()));
                        }
                        this.consulIndexes.put(context, newIndex);
                    }
                }
            } catch (Exception e) {
                // only fail fast on the initial query, otherwise just log the error
                if (firstTime && this.properties.isFailFast()) {
                    log.error("Fail fast is set and there was an error reading configuration from consul.");
                    ReflectionUtils.rethrowRuntimeException(e);
                } else if (log.isTraceEnabled()) {
                    log.trace("Error querying consul Key/Values for context '" + context + "'", e);
                } else if (log.isWarnEnabled()) {
                    // simplified one line log message in the event of an agent failure
                    log.warn("Error querying consul Key/Values for context '" + context + "'. Message: " + e.getMessage());
                }
            }
        }
    }
    firstTime = false;
}
Also used : RefreshEvent(org.springframework.cloud.endpoint.event.RefreshEvent) List(java.util.List) QueryParams(com.ecwid.consul.v1.QueryParams) Scheduled(org.springframework.scheduling.annotation.Scheduled) Timed(io.micrometer.core.annotation.Timed)

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