123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- declare(strict_types=1);
- namespace App\Job;
- use Hyperf\AsyncQueue\Job;
- use App\JsonRpc\CollectorService;
- use Hyperf\Coroutine\Exception\ParallelExecutionException;
- use Hyperf\Coroutine\Coroutine;
- use Hyperf\Coroutine\Parallel;
- /**
- * @Job(name="import")
- */
- class GatherExampleJob extends Job
- {
- public $params;
- /**
- * 任务执行失败后的重试次数,即最大执行次数为 $maxAttempts+1 次
- */
- protected int $maxAttempts = 20;
- public function __construct($params)
- {
- // 这里最好是普通数据,不要使用携带 IO 的对象,比如 PDO 对象
- $this->params = $params;
- }
- public function handle()
- {
- $collector = new CollectorService();
- $collector->goCrawler($this->params);
- }
- }
|