ManDeviceJob.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 ManDeviceJob 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. $this->data = $data;
  22. }
  23. /**
  24. * Execute the job.
  25. *
  26. * @return void
  27. */
  28. public function handle()
  29. {
  30. try{
  31. if(is_array($this->data) || is_object($this->data)){
  32. $data = json_encode($this->data);
  33. }else {
  34. $data = $this->data;
  35. }
  36. file_put_contents('send_man.txt',date('Y-m-d H:i:s').PHP_EOL . $data . PHP_EOL,8);
  37. //输出信息 测试
  38. $this->echoMessage(new ConsoleOutput());
  39. }catch (\Exception $exception){
  40. file_put_contents('send_man_error.txt',date("Y-m-d H:i:s").PHP_EOL.$exception->getMessage().PHP_EOL,8);
  41. }
  42. }
  43. protected function echoMessage(OutputInterface $output)
  44. {
  45. $output->writeln($this->data);
  46. }
  47. }