记得上下班打卡 | git大法好,push需谨慎

Commit 1f893217 authored by wangyifan's avatar wangyifan

platform 增加定时任务执行日志

parent 189a96bd
...@@ -56,19 +56,24 @@ public class PlatformGroupBuyTaskServiceImpl { ...@@ -56,19 +56,24 @@ public class PlatformGroupBuyTaskServiceImpl {
.and("expiresAt").lt(now)); .and("expiresAt").lt(now));
List<KylinGroupBuyOrderVo> orders = mongoTemplate.find(query, List<KylinGroupBuyOrderVo> orders = mongoTemplate.find(query,
KylinGroupBuyOrderVo.class, KylinGroupBuyOrderVo.class.getSimpleName()); KylinGroupBuyOrderVo.class, KylinGroupBuyOrderVo.class.getSimpleName());
int processed = 0;
int skipped = 0;
for (KylinGroupBuyOrderVo order : orders) { for (KylinGroupBuyOrderVo order : orders) {
String groupOrderId = order.getGroupOrderId(); String groupOrderId = order.getGroupOrderId();
if (!groupBuyPlatformHelper.tryLock(groupOrderId)) { if (!groupBuyPlatformHelper.tryLock(groupOrderId)) {
log.warn("拼团超时任务获取锁失败 groupOrderId={}", groupOrderId); log.warn("拼团超时任务获取锁失败 groupOrderId={}", groupOrderId);
skipped++;
continue; continue;
} }
try { try {
KylinGroupBuyOrderVo fresh = groupBuyPlatformHelper.loadFromMongo(groupOrderId); KylinGroupBuyOrderVo fresh = groupBuyPlatformHelper.loadFromMongo(groupOrderId);
if (fresh == null || !GroupBuyStatusConst.OrderStatus.PENDING.equals(fresh.getStatus())) { if (fresh == null || !GroupBuyStatusConst.OrderStatus.PENDING.equals(fresh.getStatus())) {
skipped++;
continue; continue;
} }
if (fresh.getExpiresAt() == null if (fresh.getExpiresAt() == null
|| !DateUtil.Formatter.yyyyMMddHHmmss.parse(fresh.getExpiresAt()).isBefore(LocalDateTime.now())) { || !DateUtil.Formatter.yyyyMMddHHmmss.parse(fresh.getExpiresAt()).isBefore(LocalDateTime.now())) {
skipped++;
continue; continue;
} }
fresh.setStatus(GroupBuyStatusConst.OrderStatus.FAILED); fresh.setStatus(GroupBuyStatusConst.OrderStatus.FAILED);
...@@ -95,12 +100,15 @@ public class PlatformGroupBuyTaskServiceImpl { ...@@ -95,12 +100,15 @@ public class PlatformGroupBuyTaskServiceImpl {
for (String orderTicketsId : joinedOrderTicketIds) { for (String orderTicketsId : joinedOrderTicketIds) {
refundJoinedTicket(orderTicketsId, "拼团超时未成团,全额退款"); refundJoinedTicket(orderTicketsId, "拼团超时未成团,全额退款");
} }
processed++;
} catch (Exception e) { } catch (Exception e) {
log.error("拼团超时处理失败 groupOrderId={}", groupOrderId, e); log.error("拼团超时处理失败 groupOrderId={}", groupOrderId, e);
} finally { } finally {
groupBuyPlatformHelper.unlock(groupOrderId); groupBuyPlatformHelper.unlock(groupOrderId);
} }
} }
log.info("拼团超时任务结束 now={}, hit={}, processed={}, skipped={}",
now, orders == null ? 0 : orders.size(), processed, skipped);
return true; return true;
} }
...@@ -116,25 +124,32 @@ public class PlatformGroupBuyTaskServiceImpl { ...@@ -116,25 +124,32 @@ public class PlatformGroupBuyTaskServiceImpl {
.and("remind1hSent").ne(1)); .and("remind1hSent").ne(1));
List<KylinGroupBuyOrderVo> orders = mongoTemplate.find(query, List<KylinGroupBuyOrderVo> orders = mongoTemplate.find(query,
KylinGroupBuyOrderVo.class, KylinGroupBuyOrderVo.class.getSimpleName()); KylinGroupBuyOrderVo.class, KylinGroupBuyOrderVo.class.getSimpleName());
int processed = 0;
int skipped = 0;
for (KylinGroupBuyOrderVo order : orders) { for (KylinGroupBuyOrderVo order : orders) {
String groupOrderId = order.getGroupOrderId(); String groupOrderId = order.getGroupOrderId();
if (!groupBuyPlatformHelper.tryLock(groupOrderId)) { if (!groupBuyPlatformHelper.tryLock(groupOrderId)) {
log.warn("拼团1h提醒获取锁失败 groupOrderId={}", groupOrderId); log.warn("拼团1h提醒获取锁失败 groupOrderId={}", groupOrderId);
skipped++;
continue; continue;
} }
try { try {
KylinGroupBuyOrderVo fresh = groupBuyPlatformHelper.loadFromMongo(groupOrderId); KylinGroupBuyOrderVo fresh = groupBuyPlatformHelper.loadFromMongo(groupOrderId);
if (fresh == null || !GroupBuyStatusConst.OrderStatus.PENDING.equals(fresh.getStatus())) { if (fresh == null || !GroupBuyStatusConst.OrderStatus.PENDING.equals(fresh.getStatus())) {
skipped++;
continue; continue;
} }
if (groupBuySmsSender.isRemind1hAlreadySent(fresh)) { if (groupBuySmsSender.isRemind1hAlreadySent(fresh)) {
skipped++;
continue; continue;
} }
if (fresh.getExpiresAt() == null) { if (fresh.getExpiresAt() == null) {
skipped++;
continue; continue;
} }
LocalDateTime expiresAt = DateUtil.Formatter.yyyyMMddHHmmss.parse(fresh.getExpiresAt()); LocalDateTime expiresAt = DateUtil.Formatter.yyyyMMddHHmmss.parse(fresh.getExpiresAt());
if (!expiresAt.isAfter(nowLdt) || expiresAt.isAfter(nowLdt.plusHours(1))) { if (!expiresAt.isAfter(nowLdt) || expiresAt.isAfter(nowLdt.plusHours(1))) {
skipped++;
continue; continue;
} }
try { try {
...@@ -145,12 +160,15 @@ public class PlatformGroupBuyTaskServiceImpl { ...@@ -145,12 +160,15 @@ public class PlatformGroupBuyTaskServiceImpl {
fresh.setRemind1hSent(1); fresh.setRemind1hSent(1);
fresh.setUpdatedAt(now); fresh.setUpdatedAt(now);
groupBuyPlatformHelper.saveGroup(fresh); groupBuyPlatformHelper.saveGroup(fresh);
processed++;
} catch (Exception e) { } catch (Exception e) {
log.error("拼团1h提醒处理失败 groupOrderId={}", groupOrderId, e); log.error("拼团1h提醒处理失败 groupOrderId={}", groupOrderId, e);
} finally { } finally {
groupBuyPlatformHelper.unlock(groupOrderId); groupBuyPlatformHelper.unlock(groupOrderId);
} }
} }
log.info("拼团1h提醒任务结束 now={}, deadline={}, hit={}, processed={}, skipped={}",
now, deadline, orders == null ? 0 : orders.size(), processed, skipped);
return true; return true;
} }
...@@ -189,6 +207,9 @@ public class PlatformGroupBuyTaskServiceImpl { ...@@ -189,6 +207,9 @@ public class PlatformGroupBuyTaskServiceImpl {
GroupBuyStatusConst.ActivityStatus.ENDED, LocalDateTime.now()); GroupBuyStatusConst.ActivityStatus.ENDED, LocalDateTime.now());
cacheActivity(activity); cacheActivity(activity);
} }
log.info("拼团活动调度结束 now={}, started={}, ended={}", now,
dueStartList == null ? 0 : dueStartList.size(),
dueEndList == null ? 0 : dueEndList.size());
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment