Commit 8b03052d by yinyong

新增错误排查记录

parent 3f21cf8e
......@@ -3,6 +3,7 @@ package com.bailuntec;
import com.alibaba.druid.pool.DruidDataSource;
import com.bailuntec.job.AdvertAddTaskSyncJob;
import com.bailuntec.job.AdvertResultSyncJob;
import com.bailuntec.listener.AdvertSyncJobListener;
import com.bailuntec.utils.PropertiesUtil;
import com.dangdang.ddframe.job.config.JobCoreConfiguration;
import com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration;
......@@ -26,7 +27,7 @@ public class Application {
private static final String EVENT_RDB_STORAGE_PASSWORD = propertiesUtil.getPropertyAsString("EVENT_RDB_STORAGE_PASSWORD");
public static void main(String[] args) {
new JobScheduler(createRegistryCenter(), createJobConfiguration1()).init();
new JobScheduler(createRegistryCenter(), createJobConfiguration1(), createJobEventConfiguration(), new AdvertSyncJobListener()).init();
// new JobScheduler(createRegistryCenter(), createJobConfiguration2()).init();
}
......
......@@ -13,14 +13,14 @@ import com.dangdang.ddframe.job.api.ShardingContext;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.apache.commons.lang3.StringUtils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipException;
@Slf4j
public class AdvertAddTaskSyncJob extends PointJob {
......@@ -39,13 +39,18 @@ public class AdvertAddTaskSyncJob extends PointJob {
Response response = null;
try {
do {
List<Map> list = null;
try{
Request request0 = new Request.Builder()
.url(propertiesUtil.getPropertyAsString("ACCOUNT_API"))
.addHeader("Content-Type", "application/json")
.build();
response = client.newCall(request0).execute();
AccountTokenInfo resultMap0 = JSON.parseObject(response.body().string(), AccountTokenInfo.class);
List<Map> list = resultMap0.getData();
list = resultMap0.getData();
}catch (IOException e){
throw new RuntimeException("调用百伦授权接口失败,详情:" + transform(e));
}
Map<String, String> authJsonMap = new HashMap<String, String>();
if(list != null && list.size() > 0) {
for(Map map0 : list) {
......@@ -54,7 +59,8 @@ public class AdvertAddTaskSyncJob extends PointJob {
continue;
}
authJsonMap = JSON.parseObject(authStr, Map.class);
Map<String, String> resultMap = new HashMap<>();
try{
Map<String, String> map = new HashMap<>();
map.put("reportDate", localDateTime.format(DateTimeFormatter.ofPattern("yyyyMMdd")));
map.put("metrics", propertiesUtil.getPropertyAsString("METRICS"));
......@@ -68,8 +74,13 @@ public class AdvertAddTaskSyncJob extends PointJob {
.addHeader("Content-Type", "application/json")
.build();
response = client.newCall(request).execute();
Map<String, String> resultMap = JSON.parseObject(response.body().string(), Map.class);
resultMap = JSON.parseObject(response.body().string(), Map.class);
}catch (IOException e){
throw new RuntimeException("调用广告费报告任务下发接口失败,错误详情:" + transform(e));
}
if("IN_PROGRESS".equals(resultMap.get("status"))) {
Map<String, String> resultMap2 = new HashMap<>();
try{
Request request2 = new Request.Builder()
.url(propertiesUtil.getPropertyAsString("V2_REPORTS") + resultMap.get("reportId"))
.addHeader("Authorization", "Bearer " + authJsonMap.get("access_token"))
......@@ -78,8 +89,12 @@ public class AdvertAddTaskSyncJob extends PointJob {
.addHeader("Content-Type", "application/json")
.build();
response = client.newCall(request2).execute();
Map<String, String> resultMap2 = JSON.parseObject(response.body().string(), Map.class);
resultMap2 = JSON.parseObject(response.body().string(), Map.class);
}catch (IOException e){
throw new RuntimeException("调用广告费报告下载路径错误,错误详情:" + transform(e));
}
if("SUCCESS".equals(resultMap2.get("status"))) {
try{
String location = resultMap2.get("location");
Request request3 = new Request.Builder()
.url(location)
......@@ -106,13 +121,37 @@ public class AdvertAddTaskSyncJob extends PointJob {
dcBaseFinanceAmazonMapper.upsertSelective(amazonAdvert);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Mybatis操作DB插入任务记录失败", e);
throw new RuntimeException("Mybatis操作DB插入任务记录失败,错误详情:" + transform(e));
} finally {
SessionUtil.closeSession();
}
}
gzin.close();
isr.close();
}catch (ZipException e){
log.warn("返回数据为非gz压缩格式", response.body().toString());
}catch (IOException e){
throw new RuntimeException("调用广告费报告解析接口报错,错误详情:" + transform(e));
}
}
}else{
if(job.getPageIndex() == 2) {
try{
Map errorMap = new HashMap();
Map contentMap = new HashMap();
contentMap.put("content", "帐号id:"+ map0.get("Id")+"授权失败,错误详情:"+resultMap);
errorMap.put("msgtype", "text");
errorMap.put("text", contentMap);
RequestBody errorBody = RequestBody.create(mediaType, JSON.toJSONString(errorMap));
Request request2 = new Request.Builder()
.url(propertiesUtil.getPropertyAsString("WARN_API"))
.post(errorBody)
.addHeader("Content-Type", "application/json")
.build();
response = client.newCall(request2).execute();
}catch (Exception e){
e.printStackTrace();
}
}
}
}
......@@ -129,4 +168,15 @@ public class AdvertAddTaskSyncJob extends PointJob {
}
}
}
public String transform(final Throwable cause) {
if (null == cause) {
return "";
}
StringWriter result = new StringWriter();
try (PrintWriter writer = new PrintWriter(result)) {
cause.printStackTrace(writer);
}
return result.toString();
}
}
package com.bailuntec.listener;
import com.dangdang.ddframe.job.executor.ShardingContexts;
import com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener;
public class AdvertSyncJobListener implements ElasticJobListener {
@Override
public void beforeJobExecuted(ShardingContexts shardingContexts) {
}
@Override
public void afterJobExecuted(ShardingContexts shardingContexts) {
}
}
......@@ -3,6 +3,7 @@ GETRESULT_FINANCE_URL=http://10.0.3.5:18321/outer/getresult
ACCOUNT_API=http://pams.bailuntec.com/Api/GetAccountToken?platform=Amazon
CAMPAIGNS_REPORT=https://advertising-api.amazon.com/v2/sp/campaigns/report
V2_REPORTS=https://advertising-api.amazon.com/v2/reports/
WARN_API=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=b4655a50-927a-4c3c-87ad-a900e54dcc8e
#METRICS=campaignName,campaignId,campaignStatus,campaignBudget,attributedConversions1d,attributedUnitsOrdered1d,attributedSales1d,attributedUnitsOrdered7d,attributedSales1d,impressions,clicks,cost,attributedConversions30d,attributedConversions14d,attributedConversions7d,attributedSales30d,attributedSales14d,attributedSales7d
METRICS=campaignName,campaignId,cost,currency,campaignStatus,campaignBudget,cost
......
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