MqExportPaliChapter.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 MqExportPaliChapter extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. * php artisan mq:export.pali.chapter
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'mq:export.pali.chapter';
  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_pali_chapter';
  39. $this->info(" [*] Waiting for {$queue}. To exit press CTRL+C");
  40. Log::debug('mq:export_pali_chapter 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. 'query_id' => $message->queryId,
  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. if (isset($message->token) && is_string($message->token)) {
  56. $data['--token'] = $message->token;
  57. }
  58. $ok = $this->call('export:chapter', $data);
  59. if ($ok !== 0) {
  60. Log::error('mq:export.pali.chapter upgrade:progress fail', $data);
  61. } else {
  62. $this->info('Received book='.$message->book.' result='.$ok);
  63. Log::debug('mq:export.pali.chapter done ', $data);
  64. return $ok;
  65. }
  66. });
  67. return 0;
  68. }
  69. }