Authored by wangshusheng

Merge branch 'dev' of http://git.dev.yoho.cn/yoho30/yohobuy-activity into dev

/**
*
*/
package com.yoho.activity.common.utils;
import com.netflix.config.DynamicBooleanProperty;
import com.netflix.config.DynamicPropertyFactory;
/**
* 描述:
*
* @author ping.huang
* 2016年3月8日
*/
public class PropertiesUtil {
/**
* 获取定时任务是否执行的配置值
* @return
*/
public static boolean getExecuteTask() {
DynamicBooleanProperty pro = DynamicPropertyFactory.getInstance().getBooleanProperty("activity.execute.task", false);
return pro.get();
}
}
... ...
... ... @@ -17,10 +17,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;
import com.yoho.activity.common.enums.UserTypeEnum;
import com.yoho.activity.common.utils.MapUtil;
import com.yoho.activity.common.utils.MapUtil.FunctionExPlus;
import com.yoho.activity.common.utils.PropertiesUtil;
import com.yoho.queue.dal.IDrawlineActivityDAO;
import com.yoho.queue.dal.IDrawlineUserQueueDAO;
import com.yoho.queue.dal.IDrawlineVirtualUserDAO;
... ... @@ -101,12 +101,16 @@ public class AddVirtualUserTimer {
waitAddUserMap.put(activity.getId(), waitList);
}
}
System.out.println("result= " + JSON.toJSONString(waitAddUserMap));
}
@Scheduled(fixedDelay = 60 * 1000)
public void run() {
log.info("start add virtuals");
boolean execute = PropertiesUtil.getExecuteTask();
if (!execute) {
log.info("properties is false exit task");
return;
}
//没有活动,直接退出
if (activityList == null || activityList.size() == 0) {
... ... @@ -151,7 +155,7 @@ public class AddVirtualUserTimer {
}
waitList = waitAddUserMap.get(activity.getId());
if (waitList == null || waitList.size() == 0) {
log.info("wait queue user is empty");
log.info("wait queue user is empty with activityId is {}, activityName is {}", activity.getId(), activity.getActivityName());
continue;
}
if (first.get(activity.getId()) == null) {
... ...
... ... @@ -9,6 +9,7 @@ import org.springframework.stereotype.Service;
import com.netflix.config.DynamicLongProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.yoho.activity.common.utils.PropertiesUtil;
import com.yoho.activity.queue.constant.Const;
import com.yoho.activity.queue.service.ITimeTaskService;
... ... @@ -21,21 +22,25 @@ public class LuckyUserNoticeThread {
private ITimeTaskService timeTaskService;
public LuckyUserNoticeThread(){
//(1)定时任务执行时间间隔,单位为分
DynamicLongProperty initialDelay = DynamicPropertyFactory.getInstance().getLongProperty("drawline.luckyUserNotice.interval", 120);
//(2)服务启动10后开始执行, 默认每隔2小时执行一次
Const.LUCKYUSERNOTICE_EXE.scheduleAtFixedRate(new Runnable() {
if(PropertiesUtil.getExecuteTask()){
//(1)定时任务执行时间间隔,单位为分
DynamicLongProperty initialDelay = DynamicPropertyFactory.getInstance().getLongProperty("drawline.luckyUserNotice.interval", 120);
@Override
public void run() {
logger.info("LuckyUserNotice thread start...");
//(2)服务启动10后开始执行, 默认每隔2小时执行一次
Const.LUCKYUSERNOTICE_EXE.scheduleAtFixedRate(new Runnable() {
timeTaskService.luckyUserNotice();
logger.info("LuckyUserNotice thread end.");
}
}, 10, initialDelay.get(), TimeUnit.MINUTES);
@Override
public void run() {
logger.info("LuckyUserNotice thread start...");
timeTaskService.luckyUserNotice();
logger.info("LuckyUserNotice thread end.");
}
}, 10, initialDelay.get(), TimeUnit.MINUTES);
}
}
}
... ...
... ... @@ -32,3 +32,6 @@ drawline.luckydraw.interval=1440
# ******************** drawline lucky user notice task interval(TimeUnit.MINUTES) ********************
drawline.luckyUserNotice.interval=120
#定时任务是否执行
activity.execute.task = true
... ...
... ... @@ -9,6 +9,7 @@
<property name="drawline.luckydraw.interval" defaultValue="1440" description="执行定时抽奖任务间隔" />
<property name="drawline.luckyUserNotice.interval" defaultValue="120" description="执行抽奖结果通知任务间隔" />
<property name="activity.execute.task" defaultValue="false" description="定时任务是否执行" />
</group>
<script>
<generate template="META-INF/autoconf/databases.yml" destfile="WEB-INF/classes/databases.yml" />
... ...
... ... @@ -32,3 +32,6 @@ drawline.luckydraw.interval=${drawline.luckydraw.interval}
# ******************** drawline user notice task interval(TimeUnit.MINUTES) ********************
drawline.luckyUserNotice.interval=${drawline.luckyUserNotice.interval}
#\u5B9A\u65F6\u4EFB\u52A1\u662F\u5426\u6267\u884C
activity.execute.task = ${activity.execute.task}
... ...