|
|
@@ -60,6 +60,25 @@ namespace molilian.core
|
|
|
|
|
|
if (string.IsNullOrEmpty(node.redis_server)) return 0;
|
|
|
|
|
|
+
|
|
|
+#if DEBUG
|
|
|
+ switch (node.name)
|
|
|
+ {
|
|
|
+
|
|
|
+ case "bj":
|
|
|
+ node.redis_server = "101.200.46.46:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
|
|
|
+ break;
|
|
|
+ case "gz":
|
|
|
+ node.redis_server = "8.138.110.158:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
|
|
|
+ break;
|
|
|
+ case "coupon1":
|
|
|
+ node.redis_server = "c1api.molilian.com:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=coupon";
|
|
|
+ break;
|
|
|
+ default: return 0;
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
var redis = RedisClientManager.GetRedisClient(node.redis_server);
|
|
|
return BatchInsertLogDB(limit, redis);
|
|
|
});
|
|
|
@@ -97,7 +116,7 @@ namespace molilian.core
|
|
|
|
|
|
|
|
|
stopwatch.Start();
|
|
|
- taskTotal = task_insert_parse_tb_logs(connection, transaction, limit, redis);
|
|
|
+ taskTotal = task_insert_parse_tb_logs(limit, redis);
|
|
|
total += taskTotal;
|
|
|
stopwatch.Stop();
|
|
|
log.Info($"task_insert_parse_tb_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
|
|
|
@@ -105,7 +124,7 @@ namespace molilian.core
|
|
|
stopwatch.Reset();
|
|
|
|
|
|
stopwatch.Start();
|
|
|
- taskTotal = task_insert_parse_jd_logs(connection, transaction, limit, redis);
|
|
|
+ taskTotal = task_insert_parse_jd_logs(limit, redis);
|
|
|
total += taskTotal;
|
|
|
stopwatch.Stop();
|
|
|
log.Info($"task_insert_parse_jd_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
|
|
|
@@ -113,7 +132,7 @@ namespace molilian.core
|
|
|
stopwatch.Reset();
|
|
|
|
|
|
stopwatch.Start();
|
|
|
- taskTotal = task_insert_parse_pdd_logs(connection, transaction, limit, redis);
|
|
|
+ taskTotal = task_insert_parse_pdd_logs(limit, redis);
|
|
|
total += taskTotal;
|
|
|
stopwatch.Stop();
|
|
|
log.Info($"task_insert_parse_pdd_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
|
|
|
@@ -121,7 +140,7 @@ namespace molilian.core
|
|
|
stopwatch.Reset();
|
|
|
|
|
|
stopwatch.Start();
|
|
|
- taskTotal = task_insert_parse_dy_logs(connection, transaction, limit, redis);
|
|
|
+ taskTotal = task_insert_parse_dy_logs(limit, redis);
|
|
|
total += taskTotal;
|
|
|
stopwatch.Stop();
|
|
|
log.Info($"task_insert_parse_dy_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
|
|
|
@@ -129,7 +148,7 @@ namespace molilian.core
|
|
|
stopwatch.Reset();
|
|
|
|
|
|
stopwatch.Start();
|
|
|
- taskTotal = task_insert_parse_tool_logs(connection, transaction, limit, redis);
|
|
|
+ taskTotal = task_insert_parse_tool_logs(limit, redis);
|
|
|
total += taskTotal;
|
|
|
stopwatch.Stop();
|
|
|
log.Info($"task_insert_parse_tool_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
|
|
|
@@ -145,7 +164,7 @@ namespace molilian.core
|
|
|
stopwatch.Reset();
|
|
|
|
|
|
stopwatch.Start();
|
|
|
- taskTotal = task_insert_parse_coupon_logs(connection, transaction, limit, redis);
|
|
|
+ taskTotal = task_insert_parse_coupon_logs(limit, redis);
|
|
|
total += taskTotal;
|
|
|
stopwatch.Stop();
|
|
|
log.Info($"task_insert_parse_coupon_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
|
|
|
@@ -153,7 +172,7 @@ namespace molilian.core
|
|
|
stopwatch.Reset();
|
|
|
|
|
|
stopwatch.Start();
|
|
|
- taskTotal = task_insert_parse_cps_logs(connection, transaction, limit, redis);
|
|
|
+ taskTotal = task_insert_parse_cps_logs(limit, redis);
|
|
|
total += taskTotal;
|
|
|
stopwatch.Stop();
|
|
|
log.Info($"task_insert_parse_cps_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
|
|
|
@@ -161,7 +180,7 @@ namespace molilian.core
|
|
|
stopwatch.Reset();
|
|
|
|
|
|
stopwatch.Start();
|
|
|
- taskTotal = task_insert_promotion_img_logs(connection, transaction, limit, redis);
|
|
|
+ taskTotal = task_insert_promotion_img_logs(limit, redis);
|
|
|
total += taskTotal;
|
|
|
stopwatch.Stop();
|
|
|
log.Info($"task_insert_promotion_img_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
|
|
|
@@ -169,7 +188,7 @@ namespace molilian.core
|
|
|
stopwatch.Reset();
|
|
|
|
|
|
stopwatch.Start();
|
|
|
- taskTotal = task_insert_parse_ks_logs(connection, transaction, limit, redis);
|
|
|
+ taskTotal = task_insert_parse_ks_logs(limit, redis);
|
|
|
total += taskTotal;
|
|
|
stopwatch.Stop();
|
|
|
log.Info($"task_insert_parse_ks_logs 耗时: {stopwatch.ElapsedMilliseconds} ms,\t插入记录数: {taskTotal}");
|
|
|
@@ -212,25 +231,24 @@ namespace molilian.core
|
|
|
try
|
|
|
{
|
|
|
Stopwatch stopwatch = new Stopwatch(); // 创建一个计时器
|
|
|
- LoggerLibrary log = new LoggerLibrary("debug", "BatchInsertLogDB"); // 创建日志对象
|
|
|
|
|
|
var tasks = new List<Task<int>>
|
|
|
{
|
|
|
- Task.Run(() => RunTaskWithLogging(() => task_insert_tk_logs(limit, redis), "task_insert_tk_logs", log)),
|
|
|
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_tb_logs(connection, transaction, limit, redis), "task_insert_parse_tb_logs", log)),
|
|
|
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_jd_logs(connection, transaction, limit, redis), "task_insert_parse_jd_logs", log)),
|
|
|
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_pdd_logs(connection, transaction, limit, redis), "task_insert_parse_pdd_logs", log)),
|
|
|
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_dy_logs(connection, transaction, limit, redis), "task_insert_parse_dy_logs", log)),
|
|
|
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_tool_logs(connection, transaction, limit, redis), "task_insert_parse_tool_logs", log)),
|
|
|
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_deeplink_logs(limit, redis), "task_insert_parse_deeplink_logs", log)),
|
|
|
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_coupon_logs(connection, transaction, limit, redis), "task_insert_parse_coupon_logs", log)),
|
|
|
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_cps_logs(connection, transaction, limit, redis), "task_insert_parse_cps_logs", log)),
|
|
|
- Task.Run(() => RunTaskWithLogging(() => task_insert_promotion_img_logs(connection, transaction, limit, redis), "task_insert_promotion_img_logs", log)),
|
|
|
- Task.Run(() => RunTaskWithLogging(() => task_insert_parse_ks_logs(connection, transaction, limit, redis), "task_insert_parse_ks_logs", log))
|
|
|
+ Task.Run(() => RunTaskWithLogging(() => task_insert_tk_logs(limit, redis), "task_insert_tk_logs")),
|
|
|
+ Task.Run(() => RunTaskWithLogging(() => task_insert_parse_tb_logs(limit, redis), "task_insert_parse_tb_logs")),
|
|
|
+ Task.Run(() => RunTaskWithLogging(() => task_insert_parse_jd_logs(limit, redis), "task_insert_parse_jd_logs")),
|
|
|
+ Task.Run(() => RunTaskWithLogging(() => task_insert_parse_pdd_logs(limit, redis), "task_insert_parse_pdd_logs")),
|
|
|
+ Task.Run(() => RunTaskWithLogging(() => task_insert_parse_dy_logs(limit, redis), "task_insert_parse_dy_logs")),
|
|
|
+ Task.Run(() => RunTaskWithLogging(() => task_insert_parse_tool_logs(limit, redis), "task_insert_parse_tool_logs")),
|
|
|
+ Task.Run(() => RunTaskWithLogging(() => task_insert_parse_deeplink_logs(limit, redis), "task_insert_parse_deeplink_logs")),
|
|
|
+ Task.Run(() => RunTaskWithLogging(() => task_insert_parse_coupon_logs(limit, redis), "task_insert_parse_coupon_logs")),
|
|
|
+ Task.Run(() => RunTaskWithLogging(() => task_insert_parse_cps_logs(limit, redis), "task_insert_parse_cps_logs")),
|
|
|
+ Task.Run(() => RunTaskWithLogging(() => task_insert_promotion_img_logs(limit, redis), "task_insert_promotion_img_logs")),
|
|
|
+ Task.Run(() => RunTaskWithLogging(() => task_insert_parse_ks_logs(limit, redis), "task_insert_parse_ks_logs"))
|
|
|
};
|
|
|
|
|
|
// 等待所有任务完成
|
|
|
- Task.WhenAll(tasks).Wait();
|
|
|
+ Task.WhenAll(tasks).Wait();//252行
|
|
|
|
|
|
// 计算所有任务的结果总和
|
|
|
total = tasks.Select(t => t.Result).Sum();
|
|
|
@@ -241,13 +259,36 @@ namespace molilian.core
|
|
|
{
|
|
|
//transaction.Rollback();
|
|
|
|
|
|
+
|
|
|
+ // 构建异常详细信息字符串
|
|
|
+ string detailedError = $"{ex.Message}\n" +
|
|
|
+ $"堆栈跟踪: {ex.StackTrace}\n";
|
|
|
+
|
|
|
+ if (ex.InnerException != null)
|
|
|
+ {
|
|
|
+ detailedError += $"内部异常: {ex.InnerException.Message}\n" +
|
|
|
+ $"内部堆栈跟踪: {ex.InnerException.StackTrace}\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果异常包含其他数据,也可以记录下来
|
|
|
+ if (ex.Data != null && ex.Data.Count > 0)
|
|
|
+ {
|
|
|
+ detailedError += "附加数据:\n";
|
|
|
+ foreach (var key in ex.Data.Keys)
|
|
|
+ {
|
|
|
+ detailedError += $"{key}: {ex.Data[key]}\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
_ = new LoggerLibrary("database_error", "parse_log")
|
|
|
- .Info(ex.Message, ex.StackTrace)
|
|
|
+ .Info(detailedError)
|
|
|
.SaveAsync();
|
|
|
|
|
|
+
|
|
|
NotifyCore.Notify(new NifyMessage
|
|
|
{
|
|
|
- message = $"【写入日志异常】\n{ex.Message}\n{ex.StackTrace}",
|
|
|
+ message = $"【Exception】\n{detailedError}",
|
|
|
priority = NifyMessagePriority.high,
|
|
|
tags = ["red_circle"]
|
|
|
});
|
|
|
@@ -261,8 +302,9 @@ namespace molilian.core
|
|
|
|
|
|
|
|
|
// 新增一个辅助方法来处理日志记录和任务执行
|
|
|
- private static int RunTaskWithLogging(Func<int> taskFunc, string taskName, LoggerLibrary log)
|
|
|
+ private static int RunTaskWithLogging(Func<int> taskFunc, string taskName)
|
|
|
{
|
|
|
+ LoggerLibrary log = new LoggerLibrary("debug", "BatchInsertLogDB"); // 创建日志对象
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
|
stopwatch.Start();
|
|
|
int taskTotal = taskFunc();
|