ProcessDataJob.php 1.3 KB

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