add refresh job
This commit is contained in:
+1
-1
@@ -37,7 +37,7 @@ import com.mongodb.DBObject;
|
||||
|
||||
public class DistrictInfoJob implements SimpleJob{
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(EnterpriseStatJob.class);
|
||||
private Logger logger = LoggerFactory.getLogger(DistrictInfoJob.class);
|
||||
|
||||
@Value("${FANGJIA_API_TOKEN}")
|
||||
private String token;
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.fangjia.job.youfang.job;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import com.dangdang.ddframe.job.api.ShardingContext;
|
||||
import com.dangdang.ddframe.job.api.simple.SimpleJob;
|
||||
import com.fangjia.job.common.util.DingDingMessageUtil;
|
||||
import com.fangjia.job.common.util.RestApiCallUtils;
|
||||
import com.fangjia.job.youfang.remote.FshApiRemoteService;
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.Bytes;
|
||||
import com.mongodb.DBCollection;
|
||||
import com.mongodb.DBCursor;
|
||||
import com.mongodb.DBObject;
|
||||
|
||||
/**
|
||||
* 提前刷新缓存任务
|
||||
* @author yinjihuan
|
||||
*
|
||||
*/
|
||||
public class RefreshCacheJob implements SimpleJob {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(RefreshCacheJob.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("seaweedMongoTemplate")
|
||||
private MongoTemplate seaweedMongoTemplate;
|
||||
|
||||
@Value("${fsh.url}")
|
||||
private String fshApiUrl;
|
||||
|
||||
private ExecutorService fixPool = Executors.newFixedThreadPool(1);
|
||||
|
||||
@Override
|
||||
public void execute(ShardingContext shardingContext) {
|
||||
logger.info("开始进行缓存刷新任务");
|
||||
final FshApiRemoteService fshApiRemoteService = RestApiCallUtils.getRestClient(FshApiRemoteService.class, fshApiUrl);
|
||||
DBCollection collection = seaweedMongoTemplate.getCollection("seaweed");
|
||||
DBCursor cursor = collection.find(new BasicDBObject("cat", "district").append("status", 0).append("city", "上海"),
|
||||
new BasicDBObject("city", 1).append("region", 1).append("name", 1)).addOption(Bytes.QUERYOPTION_NOTIMEOUT);
|
||||
final Semaphore semaphore = new Semaphore(5);
|
||||
while (cursor.hasNext()) {
|
||||
final DBObject data = cursor.next();
|
||||
try {
|
||||
semaphore.acquire();
|
||||
} catch (InterruptedException e1) {
|
||||
}
|
||||
fixPool.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String city = String.valueOf(data.get("city"));
|
||||
String region = String.valueOf(data.get("region"));
|
||||
String name = String.valueOf(data.get("name"));
|
||||
Map<String, Object> params = new HashMap<String,Object>();
|
||||
params.put("city", city);
|
||||
params.put("region", region);
|
||||
params.put("name", name);
|
||||
fshApiRemoteService.refreshDistrictDetailPageData(params);
|
||||
} catch(Exception e) {
|
||||
} finally {
|
||||
semaphore.release();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
logger.info("结束缓存刷新任务");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+8
@@ -61,4 +61,12 @@ public interface FshApiRemoteService {
|
||||
//小区估价接口
|
||||
@RequestLine("GET /fsh/evaluate")
|
||||
public DistrictSearchSingleDto evaluate(@QueryMap Map<String, Object> queryMap);
|
||||
|
||||
/**
|
||||
* 刷新小区详情页面缓存数据
|
||||
* @param queryMap
|
||||
* @return
|
||||
*/
|
||||
@RequestLine("GET /district/details")
|
||||
public String refreshDistrictDetailPageData(@QueryMap Map<String, Object> queryMap);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ spring.datasource.log.username=sa
|
||||
spring.datasource.log.password=G00jia
|
||||
spring.datasource.log.driver-class-name=com.mysql.jdbc.Driver
|
||||
|
||||
fsh.url=http://192.168.0.251:8086
|
||||
fsh.url=http://192.168.10.47:8086
|
||||
|
||||
zk.server-lists=192.168.10.47:2181
|
||||
zk.namespace=fangjia-job-youfang-test
|
||||
|
||||
@@ -16,7 +16,7 @@ spring.datasource.log.username=sa
|
||||
spring.datasource.log.password=G00jia
|
||||
spring.datasource.log.driver-class-name=com.mysql.jdbc.Driver
|
||||
|
||||
fsh.url=http://192.168.0.251:8086
|
||||
fsh.url=http://192.168.10.47:8086
|
||||
|
||||
zk.server-lists=192.168.10.47:2181
|
||||
zk.namespace=fangjia-job-youfang-test
|
||||
|
||||
@@ -103,4 +103,14 @@
|
||||
|
||||
</job:simple>
|
||||
|
||||
<!-- 有房小区详情缓存刷新任务-->
|
||||
<job:simple id="refreshCacheJob" class="com.fangjia.job.youfang.job.RefreshCacheJob" registry-center-ref="regCenter"
|
||||
sharding-total-count="1" cron="0 30 11 * * ?" sharding-item-parameters="" disabled="true"
|
||||
failover="true" description="【有房】 有房小区详情缓存刷新任务"
|
||||
overwrite="true" event-trace-rdb-data-source="elasticJobLog" job-exception-handler="com.fangjia.job.youfang.handler.CustomJobExceptionHandler">
|
||||
|
||||
<job:listener class="com.fangjia.job.youfang.listener.MessageElasticJobListener"></job:listener>
|
||||
|
||||
</job:simple>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user