2
0

MqExport.php 1.9 KB

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