echoapi-cron-scheduler-batch 1.0.22 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +16 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -333,13 +333,22 @@ class CronScheduler {
|
|
|
333
333
|
try {
|
|
334
334
|
// 1. 读取结果文件 (.res)
|
|
335
335
|
const resFiles = fs.readdirSync(this.paths.results).filter(f => f.startsWith(executionId) && f.endsWith('.res'));
|
|
336
|
-
|
|
336
|
+
// 使用对象或 Map 来存储,Key 是 unitIndex
|
|
337
|
+
const resultsMap = {};
|
|
338
|
+
const rawResults = [];
|
|
339
|
+
resFiles.forEach(f => {
|
|
337
340
|
const p = path.join(this.paths.results, f);
|
|
338
341
|
const data = JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
342
|
+
|
|
343
|
+
// 从文件名提取真正的 unitIndex (例如: executionId_5.res -> 5)
|
|
344
|
+
const uIdx = f.split('_').pop().split('.')[0];
|
|
345
|
+
resultsMap[uIdx] = data; // 精确绑定
|
|
346
|
+
|
|
347
|
+
rawResults.push(data); // 用于统计计算
|
|
339
348
|
try { fs.unlinkSync(p); } catch (e) { }
|
|
340
|
-
return data;
|
|
341
349
|
});
|
|
342
350
|
|
|
351
|
+
|
|
343
352
|
const finalPayload = this._calculateStats(rawResults, record, executionId);
|
|
344
353
|
|
|
345
354
|
// 2. 发送汇总请求
|
|
@@ -357,8 +366,9 @@ class CronScheduler {
|
|
|
357
366
|
console.log(`✨ [Report] 汇总成功! ID: ${newReportId},开始循环处理 3 个分片...`);
|
|
358
367
|
|
|
359
368
|
// 3. 查找步骤文件 (.steps)
|
|
360
|
-
const stepFiles = fs.readdirSync(this.paths.results)
|
|
361
|
-
|
|
369
|
+
const stepFiles = fs.readdirSync(this.paths.results)
|
|
370
|
+
.filter(f => f.startsWith(executionId) && f.endsWith('.steps'))
|
|
371
|
+
.sort((a, b) => parseInt(a.split('_').pop()) - parseInt(b.split('_').pop()));
|
|
362
372
|
// 使用 for...of 配合 await,这是最稳健的顺序执行方式
|
|
363
373
|
for (const f of stepFiles) {
|
|
364
374
|
const stepPath = path.join(this.paths.results, f);
|
|
@@ -366,9 +376,9 @@ class CronScheduler {
|
|
|
366
376
|
const stepsData = JSON.parse(fs.readFileSync(stepPath, 'utf8'));
|
|
367
377
|
|
|
368
378
|
// 提取 unitIndex 以获取正确的 project_id/testing_id
|
|
369
|
-
const unitIndex = f.
|
|
379
|
+
const unitIndex = f.split('_').pop().split('.')[0];
|
|
370
380
|
// 找到对应的结果数据
|
|
371
|
-
const unitData =
|
|
381
|
+
const unitData = resultsMap[unitIndex] || {};
|
|
372
382
|
|
|
373
383
|
console.log(`📤 [Detail] 正在发送分片 #${unitIndex},数据量: ${stepsData.length} 条`);
|
|
374
384
|
|