| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace App\Console\Commands;
- use App\Http\Api\Mq;
- use App\Tools\Tools;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Log;
- class MqProgress extends Command
- {
- /**
- * The name and signature of the console command.
- * php artisan mq:progress
- *
- * @var string
- */
- protected $signature = 'mq:progress';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- if (Tools::isStop()) {
- Log::info('mq:progress. .stop exit');
- return 0;
- }
- $queue = 'progress';
- $this->info(" [*] Waiting for {$queue}. To exit press CTRL+C");
- Log::debug('mq:progress start.');
- Mq::worker($queue, function ($message) {
- $data = [
- '--book' => $message->book,
- '--para' => $message->para,
- '--channel' => $message->channel,
- ];
- $ok1 = $this->call('upgrade:progress.para', $data);
- if ($ok1 !== 0) {
- Log::error('mq:progress upgrade:progress.para fail', $data);
- }
- $ok2 = $this->call('upgrade:progress.chapter', $data);
- if ($ok2 !== 0) {
- Log::error('mq:progress upgrade:progress.chapter fail', $data);
- }
- Log::debug('mq:progress: done book='.$message->book.' progress='.$ok1.' chapter='.$ok2);
- return $ok1 + $ok2;
- });
- return 0;
- }
- }
|