MqExportArticle.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. ];
  46. if(isset($message->token) && is_string($message->token)){
  47. $data['--token'] = $message->token;
  48. }
  49. if(isset($message->anthology) && is_string($message->anthology)){
  50. $data['--anthology'] = $message->anthology;
  51. }
  52. if(isset($message->channel) && is_string($message->channel)){
  53. $data['--channel'] = $message->channel;
  54. }
  55. $ok = $this->call('export:article',$data);
  56. if($ok !== 0){
  57. Log::error('mq:export.article fail',$data);
  58. }else{
  59. $this->info("Received article id=".$message->id.' result='.$ok);
  60. Log::debug("mq:export.article done ",$data);
  61. return $ok;
  62. }
  63. });
  64. return 0;
  65. }
  66. }