| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace App\Console\Commands;
- use App\Http\Api\Mq;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Log;
- class MqExportArticle extends Command
- {
- /**
- * The name and signature of the console command.
- * php artisan mq:export.article
- *
- * @var string
- */
- protected $signature = 'mq:export.article';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '导出文章';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- $exchange = 'router';
- $queue = 'export_article';
- $this->info(" [*] Waiting for {$queue}. To exit press CTRL+C");
- Log::debug('mq:export_article start.');
- Mq::worker($exchange, $queue, function ($message) {
- $data = [
- 'id' => $message->id,
- '--format' => $message->format,
- 'query_id' => $message->queryId,
- '--origin' => $message->origin,
- '--translation' => $message->translation,
- ];
- if (isset($message->token) && is_string($message->token)) {
- $data['--token'] = $message->token;
- }
- if (isset($message->anthology) && is_string($message->anthology)) {
- $data['--anthology'] = $message->anthology;
- }
- if (isset($message->channel) && is_string($message->channel)) {
- $data['--channel'] = $message->channel;
- }
- $ok = $this->call('export:article', $data);
- if ($ok !== 0) {
- Log::error('mq:export.article fail', $data);
- } else {
- $this->info('Received article id='.$message->id.' result='.$ok);
- Log::debug('mq:export.article done ', $data);
- return $ok;
- }
- });
- return 0;
- }
- }
|