feat(bas): dispatch阶段生成run_id并透传到job便于复盘

This commit is contained in:
萝卜
2026-03-17 18:04:14 +08:00
parent 7f1f5a6887
commit e1d5cee52e
2 changed files with 15 additions and 2 deletions

View File

@@ -29,6 +29,8 @@ class BatchActivateSubscriptionsJob implements ShouldQueue
public int $processed;
public string $runId;
/**
* @param int[] $orderIds
*/
@@ -40,6 +42,7 @@ class BatchActivateSubscriptionsJob implements ShouldQueue
int $limit,
int $matchedTotal,
int $processed,
string $runId = '',
) {
$this->orderIds = array_values(array_map('intval', $orderIds));
$this->adminId = $adminId;
@@ -48,12 +51,17 @@ class BatchActivateSubscriptionsJob implements ShouldQueue
$this->limit = $limit;
$this->matchedTotal = $matchedTotal;
$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
{
// 批次号:用于把一次队列批量执行关联起来,便于后续追溯/筛选/可观测。
$runId = 'BAS' . now()->format('YmdHis') . str_pad((string) random_int(1, 9999), 4, '0', STR_PAD_LEFT);
$runId = (string) $this->runId;
$success = 0;
$failed = 0;