TestJob.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Module\Test\Jobs;
  3. use App\Module\Test\Models\Test;
  4. use UCore\Queue\QueueJob;
  5. /**
  6. * 测试队列任务类
  7. *
  8. * 用于测试和调试目的的队列任务类。
  9. * 此类主要在开发阶段使用,用于测试队列系统的功能。
  10. * 不建议在生产环境中使用此队列任务类。
  11. */
  12. class TestJob extends QueueJob
  13. {
  14. /**
  15. * 测试模型实例
  16. *
  17. * @var Test
  18. */
  19. protected Test $test;
  20. /**
  21. * 创建任务实例
  22. *
  23. * @param Test $test
  24. */
  25. public function __construct(Test $test)
  26. {
  27. $this->test = $test;
  28. parent::__construct(['test_id' => $test->id]);
  29. }
  30. /**
  31. * 执行任务
  32. *
  33. * @return bool
  34. */
  35. public function run(): bool
  36. {
  37. // 任务处理逻辑
  38. return true;
  39. }
  40. /**
  41. * 获取任务数据
  42. *
  43. * @return array
  44. */
  45. public function payload()
  46. {
  47. return [
  48. 'test_id' => $this->test->id,
  49. 'test_data' => $this->test->toArray()
  50. ];
  51. }
  52. }