BatchTaskJob.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Jobs;
  3. use App\Exceptions\ErrorException;
  4. use App\Services\BatchService;
  5. use App\Services\LogService;
  6. use App\Traits\TestableInstant;
  7. use Illuminate\Bus\Queueable;
  8. use Illuminate\Contracts\Queue\ShouldQueue;
  9. use Illuminate\Foundation\Bus\Dispatchable;
  10. use Illuminate\Queue\InteractsWithQueue;
  11. use Illuminate\Queue\SerializesModels;
  12. class BatchTaskJob implements ShouldQueue
  13. {
  14. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  15. use TestableInstant;
  16. /** @var $batchService BatchService */
  17. protected $batchService;
  18. protected $batches;
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @param $batches
  23. */
  24. public function __construct($batches)
  25. {
  26. $this->batches=$batches;
  27. LogService::log(__METHOD__,'BatchTaskJob','波次任务注册:'.json_encode($this->batches));
  28. }
  29. /**
  30. * Execute the job.
  31. *
  32. * @return void
  33. */
  34. public function handle()
  35. {
  36. LogService::log(__METHOD__,'BatchTaskJob','波次任务执行0:');
  37. if(!$this->batches)
  38. throw new ErrorException('波次任务中波次不存在!');
  39. LogService::log(__METHOD__,'BatchTaskJob','波次任务执行1:'.json_encode($this->batches));
  40. $this->instant($this->batchService, 'BatchService');
  41. $this->batchService->assignTasks($this->batches); //在这里为波次注册任务执行!
  42. }
  43. }