- 为多个广播事件添加 retryUntil 方法,设置派发后 30 秒内必须执行,否则丢弃 - 修改 LotteryDrawTickCommand handle,添加异常捕获及错误日志,保证失败时返回 FAILURE - 修改 LotteryHallCountdownCommand handle,添加异常捕获及错误日志,超时情况写入警告日志 - 针对 SettlementOrchestrator 和 DrawHallSnapshotBuilder 查询结果添加限制,防止数据量过大 - 调整计划任务 withoutOverlapping 调用,增加 expiresAt 参数避免任务锁死 - 更新 .env.example,完善本地开发与生产环境部署说明及日志配置说明 - 移除 e2e 相关测试代码、配置及依赖,精简项目体积
70 lines
2.2 KiB
PHP
70 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Events;
|
|
|
|
use Illuminate\Broadcasting\Channel;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
|
|
|
/** Jackpot 爆池公共广播:`jackpot.burst` */
|
|
final class JackpotBurstBroadcast implements ShouldBroadcast
|
|
{
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
/** 异步广播队列 */
|
|
public string $queue = 'broadcasts';
|
|
|
|
/** 最多重试 3 次 */
|
|
public int $tries = 3;
|
|
|
|
/** 单任务超时 10 秒 */
|
|
public int $timeout = 10;
|
|
|
|
/** 广播时效性保护:派发后 30 秒内必须开始执行,否则丢弃 */
|
|
public function retryUntil(): \DateTimeInterface
|
|
{
|
|
return now()->addSeconds(30);
|
|
}
|
|
|
|
public function __construct(
|
|
public readonly int $drawId,
|
|
public readonly string $drawNo,
|
|
public readonly string $firstPrizeNumber,
|
|
public readonly string $currencyCode,
|
|
public readonly int $totalPayoutAmount,
|
|
public readonly int $winnerCount,
|
|
public readonly string $triggerType,
|
|
public readonly int $poolAmountAfter,
|
|
public readonly int $emittedAtMs,
|
|
) {}
|
|
|
|
/** @return array<int, Channel> */
|
|
public function broadcastOn(): array
|
|
{
|
|
return [new Channel('lottery-hall')];
|
|
}
|
|
|
|
public function broadcastAs(): string
|
|
{
|
|
return 'jackpot.burst';
|
|
}
|
|
|
|
/** @return array{draw_id: int, draw_no: string, first_prize_number: string, currency_code: string, total_payout_amount: int, winner_count: int, trigger_type: string, pool_amount_after: int, emitted_at_ms: int} */
|
|
public function broadcastWith(): array
|
|
{
|
|
return [
|
|
'draw_id' => $this->drawId,
|
|
'draw_no' => $this->drawNo,
|
|
'first_prize_number' => $this->firstPrizeNumber,
|
|
'currency_code' => $this->currencyCode,
|
|
'total_payout_amount' => $this->totalPayoutAmount,
|
|
'winner_count' => $this->winnerCount,
|
|
'trigger_type' => $this->triggerType,
|
|
'pool_amount_after' => $this->poolAmountAfter,
|
|
'emitted_at_ms' => $this->emittedAtMs,
|
|
];
|
|
}
|
|
}
|