FailedJobController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace App\Module\System\AdminControllers;
  3. use App\Module\System\Models\FailedJob;
  4. use Dcat\Admin\Grid;
  5. use Dcat\Admin\Show;
  6. use Spatie\RouteAttributes\Attributes\Resource;
  7. use UCore\DcatAdmin\AdminController;
  8. use UCore\DcatAdmin\FilterHelper;
  9. use UCore\DcatAdmin\GridHelper;
  10. use UCore\DcatAdmin\ShowHelper;
  11. /**
  12. * 失败队列任务管理控制器
  13. */
  14. #[Resource('failed-jobs', names: 'dcat.admin.failed-jobs')]
  15. class FailedJobController extends AdminController
  16. {
  17. /**
  18. * 页面标题
  19. *
  20. * @var string
  21. */
  22. protected $title = '失败队列任务管理';
  23. /**
  24. * 列表页面
  25. *
  26. * @return Grid
  27. */
  28. protected function grid()
  29. {
  30. return Grid::make(new FailedJob(), function (Grid $grid) {
  31. $helper = new GridHelper($grid, $this);
  32. $helper->columnId();
  33. $grid->column('uuid', 'UUID')->copyable();
  34. $grid->column('queue', '队列名称')->label('primary');
  35. $grid->column('connection', '连接名称')->label('info');
  36. $grid->column('job_class', '任务类')->display(function ($value) {
  37. if (!$value) return '';
  38. $parts = explode('\\', $value);
  39. return end($parts);
  40. });
  41. $grid->column('exception_class', '异常类')->display(function ($value) {
  42. if (!$value) return '';
  43. $parts = explode('\\', $value);
  44. return end($parts);
  45. })->label('danger');
  46. $grid->column('exception_message', '异常消息')->limit(50);
  47. $grid->column('failed_at_formatted', '失败时间')->sortable();
  48. // 筛选器
  49. $grid->filter(function (Grid\Filter $filter) {
  50. $helper = new FilterHelper($filter, $this);
  51. $filter->like('queue', '队列名称');
  52. $filter->like('connection', '连接名称');
  53. $filter->like('uuid', 'UUID');
  54. $filter->between('failed_at', '失败时间')->datetime();
  55. $filter->like('exception', '异常信息');
  56. });
  57. // 禁用新增、编辑
  58. $grid->disableCreateButton();
  59. $grid->disableEditButton();
  60. // 排序
  61. $grid->model()->orderBy('id', 'desc');
  62. // 分页
  63. $grid->paginate(20);
  64. });
  65. }
  66. /**
  67. * 详情页面
  68. *
  69. * @param mixed $id
  70. * @return Show
  71. */
  72. protected function detail($id)
  73. {
  74. return Show::make($id, new FailedJob(), function (Show $show) {
  75. $helper = new ShowHelper($show, $this);
  76. $show->field('id', 'ID');
  77. $show->field('uuid', 'UUID');
  78. $show->field('queue', '队列名称');
  79. $show->field('connection', '连接名称');
  80. $show->field('job_class', '任务类');
  81. $show->field('exception_class', '异常类');
  82. $show->field('exception_message', '异常消息');
  83. $show->field('failed_at_formatted', '失败时间');
  84. $show->field('payload', '任务载荷')->json();
  85. $show->field('exception', '完整异常信息')->code();
  86. // 禁用编辑
  87. $show->disableEditButton();
  88. });
  89. }
  90. }