MqExport.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Http\Api\Mq;
  5. use Illuminate\Support\Facades\Log;
  6. class MqExport extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. * php artisan mq:export
  11. * @var string
  12. */
  13. protected $signature = 'mq:export';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '导出功能用的消息队列';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. $exchange = 'router';
  37. $queue = 'export';
  38. $this->info(" [*] Waiting for {$queue}. To exit press CTRL+C");
  39. Log::debug("mq:progress start.");
  40. Mq::worker($exchange,$queue,function ($message){
  41. $data = [
  42. 'book'=>$message->book,
  43. 'para'=>$message->para,
  44. 'channel'=>$message->channel,
  45. '--format'=>$message->format,
  46. 'filename'=>$message->filename,
  47. ];
  48. if(isset($message->origin) && is_string($message->origin)){
  49. $data['--origin'] = $message->origin;
  50. }
  51. if(isset($message->translation) && is_string($message->translation)){
  52. $data['--translation'] = $message->translation;
  53. }
  54. $ok = $this->call('export:chapter',$data);
  55. if($ok !== 0){
  56. Log::error('mq:progress upgrade:progress fail',$data);
  57. }else{
  58. $this->info("Received book=".$message->book.' result='.$ok);
  59. Log::debug("mq:export: done ",$data);
  60. return $ok;
  61. }
  62. });
  63. return 0;
  64. }
  65. }