HeartbeatV3Controller.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Exceptions\BusinessException;
  4. use App\Http\Resources\HeartbeatV3Resource;
  5. class HeartbeatV3Controller extends Controller
  6. {
  7. /**
  8. * 心跳
  9. *
  10. * 取代 `GET /v2/heartbeat`(`HeartbeatController@index`)。v2 那份在
  11. * dashboard-v4 下线前原样保留,不要改动。
  12. *
  13. * **这不是健康检查。** 它不查数据库、不查 OpenSearch / RabbitMQ / Cache,
  14. * 只回答一件事:进程还在服务吗、是不是被运维停机了。供前端与负载均衡做
  15. * 存活探测(liveness)用,开销接近零,可以高频调用。
  16. *
  17. * 真正的健康检查是 `GET /v2/health-check`(会逐项探测外部依赖并返回 checks
  18. * 明细),将来单独迁为 `/v3/health-check`,与本端点是两件事,不要混用。
  19. *
  20. * 仓库根目录存在 `.stop` 文件时返回 503(运维停机开关),此时响应体是
  21. * RFC 9457 Problem Details 而非正常结构。
  22. *
  23. * @unauthenticated
  24. *
  25. * @responseStatus 503 服务已进入停机维护状态
  26. */
  27. public function show(): HeartbeatV3Resource
  28. {
  29. if (file_exists(base_path('.stop'))) {
  30. // 用 BusinessException 而不是 abort(503):兜底处理器会屏蔽 5xx 的 detail
  31. // (防止泄露内部错误),而停机是预期状态,维护文案必须原样送到客户端
  32. throw new BusinessException(__('site.maintenance'), 503, 'maintenance');
  33. }
  34. return HeartbeatV3Resource::make([
  35. 'status' => 'ok',
  36. 'checked_at' => now(),
  37. ]);
  38. }
  39. }