feat(bas): dispatch阶段生成run_id并透传到job便于复盘
This commit is contained in:
@@ -1620,6 +1620,10 @@ class PlatformOrderController extends Controller
|
|||||||
return redirect()->back()->with('warning', '检测到刚刚已提交过同一批次的 BAS 任务(1 分钟内)。为避免重复投递,本次未再次提交。');
|
return redirect()->back()->with('warning', '检测到刚刚已提交过同一批次的 BAS 任务(1 分钟内)。为避免重复投递,本次未再次提交。');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// run_id:用于把一次批量执行关联起来,便于后续追溯/筛选/可观测。
|
||||||
|
// 说明:run_id 在投递阶段就生成,这样运营在页面成功提示里即可复制 run_id 并进入批次复盘页。
|
||||||
|
$runId = 'BAS' . now()->format('YmdHis') . str_pad((string) random_int(1, 9999), 4, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
\App\Jobs\BatchActivateSubscriptionsJob::dispatch(
|
\App\Jobs\BatchActivateSubscriptionsJob::dispatch(
|
||||||
$orderIds,
|
$orderIds,
|
||||||
(int) $admin->id,
|
(int) $admin->id,
|
||||||
@@ -1628,9 +1632,10 @@ class PlatformOrderController extends Controller
|
|||||||
(int) $limit,
|
(int) $limit,
|
||||||
(int) $matchedTotal,
|
(int) $matchedTotal,
|
||||||
(int) $processed,
|
(int) $processed,
|
||||||
|
(string) $runId,
|
||||||
);
|
);
|
||||||
|
|
||||||
return redirect()->back()->with('success', '批量同步订阅任务已提交到队列:命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条(limit=' . $limit . ')。');
|
return redirect()->back()->with('success', '批量同步订阅任务已提交到队列:命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条(limit=' . $limit . ',run_id=' . $runId . ')。');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function batchMarkPaidAndActivate(Request $request, SubscriptionActivationService $service): RedirectResponse
|
public function batchMarkPaidAndActivate(Request $request, SubscriptionActivationService $service): RedirectResponse
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ class BatchActivateSubscriptionsJob implements ShouldQueue
|
|||||||
|
|
||||||
public int $processed;
|
public int $processed;
|
||||||
|
|
||||||
|
public string $runId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int[] $orderIds
|
* @param int[] $orderIds
|
||||||
*/
|
*/
|
||||||
@@ -40,6 +42,7 @@ class BatchActivateSubscriptionsJob implements ShouldQueue
|
|||||||
int $limit,
|
int $limit,
|
||||||
int $matchedTotal,
|
int $matchedTotal,
|
||||||
int $processed,
|
int $processed,
|
||||||
|
string $runId = '',
|
||||||
) {
|
) {
|
||||||
$this->orderIds = array_values(array_map('intval', $orderIds));
|
$this->orderIds = array_values(array_map('intval', $orderIds));
|
||||||
$this->adminId = $adminId;
|
$this->adminId = $adminId;
|
||||||
@@ -48,12 +51,17 @@ class BatchActivateSubscriptionsJob implements ShouldQueue
|
|||||||
$this->limit = $limit;
|
$this->limit = $limit;
|
||||||
$this->matchedTotal = $matchedTotal;
|
$this->matchedTotal = $matchedTotal;
|
||||||
$this->processed = $processed;
|
$this->processed = $processed;
|
||||||
|
|
||||||
|
// 说明:优先使用投递时生成的 run_id(便于控制台立即可见/可复制);若未提供则在 job 内兜底生成。
|
||||||
|
$this->runId = trim($runId) !== ''
|
||||||
|
? (string) $runId
|
||||||
|
: ('BAS' . now()->format('YmdHis') . str_pad((string) random_int(1, 9999), 4, '0', STR_PAD_LEFT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(SubscriptionActivationService $service): void
|
public function handle(SubscriptionActivationService $service): void
|
||||||
{
|
{
|
||||||
// 批次号:用于把一次队列批量执行关联起来,便于后续追溯/筛选/可观测。
|
// 批次号:用于把一次队列批量执行关联起来,便于后续追溯/筛选/可观测。
|
||||||
$runId = 'BAS' . now()->format('YmdHis') . str_pad((string) random_int(1, 9999), 4, '0', STR_PAD_LEFT);
|
$runId = (string) $this->runId;
|
||||||
|
|
||||||
$success = 0;
|
$success = 0;
|
||||||
$failed = 0;
|
$failed = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user