BatchTaskJob.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. /**
  13. * @Deprecated 波次任务同步
  14. */
  15. class BatchTaskJob implements ShouldQueue
  16. {
  17. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  18. use TestableInstant;
  19. /** @var $batchService BatchService */
  20. protected $batchService;
  21. protected $batches;
  22. /**
  23. * Create a new job instance.
  24. *
  25. * @param $batches
  26. */
  27. public function __construct($batches)
  28. {
  29. $this->batches=$batches;
  30. LogService::log(__METHOD__,'BatchTaskJob','波次任务注册:'.json_encode($this->batches));
  31. }
  32. /**
  33. * Execute the job.
  34. *
  35. * @return void
  36. */
  37. public function handle()
  38. {
  39. LogService::log(__METHOD__,'BatchTaskJob','波次任务执行0:');
  40. if(!$this->batches)
  41. throw new ErrorException('波次任务中波次不存在!');
  42. LogService::log(__METHOD__,'BatchTaskJob','波次任务执行1:'.json_encode($this->batches));
  43. $this->instant($this->batchService, 'BatchService');
  44. $this->batchService->assignTasks($this->batches); //在这里为波次注册任务执行!
  45. }
  46. }