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

Commit 1f893217 authored by wangyifan's avatar wangyifan

platform 增加定时任务执行日志

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