parent
58943979ac
commit
af92ad23c2
@ -0,0 +1,21 @@
|
||||
package com.xjs.business.webmagic;
|
||||
|
||||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.business.webmagic.factory.RemoteWebmagicWeiXinSouGouFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* 内部 调用 微信搜狗 爬虫定时任务feign
|
||||
* @author xiejs
|
||||
* @since 2022-02-22
|
||||
*/
|
||||
@FeignClient(contextId = "remoteWebmagicWeiXinSouGouFeign",
|
||||
value = ServiceNameConstants.BUSINESS_WEBMAGIC_SERVICE,
|
||||
fallbackFactory = RemoteWebmagicWeiXinSouGouFactory.class)
|
||||
public interface RemoteWebmagicWeiXinSouGouFeign {
|
||||
|
||||
@GetMapping("/weixin_sougou/taskForPRC")
|
||||
R WeiXinSouGouTaskForPRC() ;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.xjs.business.webmagic.factory;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.business.webmagic.RemoteWebmagicWeiXinSouGouFeign;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 内部 调用 微信搜狗 爬虫定时任务feign降级
|
||||
* @author xiejs
|
||||
* @since 2022-02-22
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class RemoteWebmagicWeiXinSouGouFactory implements FallbackFactory<RemoteWebmagicWeiXinSouGouFeign> {
|
||||
@Override
|
||||
public RemoteWebmagicWeiXinSouGouFeign create(Throwable cause) {
|
||||
return new RemoteWebmagicWeiXinSouGouFeign() {
|
||||
@Override
|
||||
public R WeiXinSouGouTaskForPRC() {
|
||||
log.error("微信搜狗 爬虫定时任务 降级------服务可能正在运行");
|
||||
return R.fail("降级处理------服务可能正在运行");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.xjs.job.task.webmagic;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.business.webmagic.RemoteWebmagicWeiXinSouGouFeign;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
/**
|
||||
* 爬虫 微信搜狗 定时任务
|
||||
* @author xiejs
|
||||
* @since 2022-02-22
|
||||
*/
|
||||
@Component("WeiXinSouGouTask")
|
||||
@Log4j2
|
||||
public class WeiXinSouGouTask {
|
||||
|
||||
@Resource
|
||||
private RemoteWebmagicWeiXinSouGouFeign remoteWebmagicWeiXinSouGouFeign;
|
||||
|
||||
public void weiXinSouGou() {
|
||||
log.info("---------------爬虫-微信搜狗定时任务Start-------------------");
|
||||
LocalDateTime localDateTime1 = DateUtil.date().toLocalDateTime();
|
||||
|
||||
R r = remoteWebmagicWeiXinSouGouFeign.WeiXinSouGouTaskForPRC();
|
||||
|
||||
log.info("爬虫-微信搜狗定时任务结果:code={},msg={},data={}",r.getCode(),r.getMsg(),r.getData());
|
||||
LocalDateTime localDateTime2 = DateUtil.date().toLocalDateTime();
|
||||
long between = ChronoUnit.MILLIS.between(localDateTime1, localDateTime2);
|
||||
log.info("爬虫-微信搜狗定时任务Job耗费时间:{}ms", between);
|
||||
log.info("---------------爬虫-微信搜狗定时任务end---------------------");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue