MqExportPaliChapter.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. $queue = 'export_pali_chapter';
  38. $this->info(" [*] Waiting for {$queue}. To exit press CTRL+C");
  39. Log::debug('mq:export_pali_chapter start.');
  40. Mq::worker($queue, function ($message) {
  41. $data = [
  42. 'book' => $message->book,
  43. 'para' => $message->para,
  44. 'channel' => $message->channel,
  45. '--format' => $message->format,
  46. 'query_id' => $message->queryId,
  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. if (isset($message->token) && is_string($message->token)) {
  55. $data['--token'] = $message->token;
  56. }
  57. $ok = $this->call('export:chapter', $data);
  58. if ($ok !== 0) {
  59. Log::error('mq:export.pali.chapter export:chapter fail', $data);
  60. } else {
  61. $this->info('Received book='.$message->book.' result='.$ok);
  62. Log::debug('mq:export.pali.chapter done ', $data);
  63. return $ok;
  64. }
  65. });
  66. return 0;
  67. }
  68. }