GatherExampleJob.php 784 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Job;
  4. use Hyperf\AsyncQueue\Job;
  5. use App\JsonRpc\CollectorService;
  6. use Hyperf\Coroutine\Exception\ParallelExecutionException;
  7. use Hyperf\Coroutine\Coroutine;
  8. use Hyperf\Coroutine\Parallel;
  9. /**
  10. * @Job(name="import")
  11. */
  12. class GatherExampleJob extends Job
  13. {
  14. public $params;
  15. /**
  16. * 任务执行失败后的重试次数,即最大执行次数为 $maxAttempts+1 次
  17. */
  18. protected int $maxAttempts = 20;
  19. public function __construct($params)
  20. {
  21. // 这里最好是普通数据,不要使用携带 IO 的对象,比如 PDO 对象
  22. $this->params = $params;
  23. }
  24. public function handle()
  25. {
  26. $collector = new CollectorService();
  27. $collector->goCrawler($this->params);
  28. }
  29. }