ProcessDataJob.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Jobs;
  3. use App\Service\ClearDataService;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. use Symfony\Component\Console\Output\ConsoleOutput;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. class ProcessDataJob implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  14. protected $data;
  15. /**
  16. * Create a new job instance.
  17. *
  18. * @return void
  19. */
  20. public function __construct($data)
  21. {
  22. $this->data = $data;
  23. }
  24. /**
  25. * Execute the job.
  26. *
  27. * @return void
  28. */
  29. public function handle()
  30. {
  31. //标记
  32. file_put_contents('record.txt',json_encode($this->data) . PHP_EOL,8);
  33. //处理数据
  34. $return = ClearDataService::clearData($this->data);
  35. //传递数据给下一个队列
  36. dispatch(new SendDataJob($return))->onQueue('cloud_device');
  37. //输出信息
  38. $this->echoMessage(new ConsoleOutput());
  39. }
  40. protected function echoMessage(OutputInterface $output)
  41. {
  42. $output->writeln(json_encode($this->data));
  43. }
  44. }