MqExportArticle.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 MqExportArticle extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. * php artisan mq:export.article
  11. * @var string
  12. */
  13. protected $signature = 'mq:export.article';
  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_article';
  38. $this->info(" [*] Waiting for {$queue}. To exit press CTRL+C");
  39. Log::debug("mq:export_article start.");
  40. Mq::worker($exchange,$queue,function ($message){
  41. $data = [
  42. 'id'=>$message->id,
  43. '--format'=>$message->format,
  44. 'query_id'=>$message->queryId,
  45. '--origin'=>$message->origin,
  46. '--translation'=>$message->translation,
  47. ];
  48. if(isset($message->token) && is_string($message->token)){
  49. $data['--token'] = $message->token;
  50. }
  51. if(isset($message->anthology) && is_string($message->anthology)){
  52. $data['--anthology'] = $message->anthology;
  53. }
  54. if(isset($message->channel) && is_string($message->channel)){
  55. $data['--channel'] = $message->channel;
  56. }
  57. $ok = $this->call('export:article',$data);
  58. if($ok !== 0){
  59. Log::error('mq:export.article fail',$data);
  60. }else{
  61. $this->info("Received article id=".$message->id.' result='.$ok);
  62. Log::debug("mq:export.article done ",$data);
  63. return $ok;
  64. }
  65. });
  66. return 0;
  67. }
  68. }