MqWbwAnalyses.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Http\Api\Mq;
  4. use App\Tools\Tools;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\Log;
  7. class MqWbwAnalyses extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'mq:wbw.analyses';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Command 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. if (Tools::isStop()) {
  38. return 0;
  39. }
  40. $exchange = 'router';
  41. $queue = 'wbw-analyses';
  42. $this->info(" [*] Waiting for {$queue}. To exit press CTRL+C");
  43. Log::debug('mq:wbw.analyses start.');
  44. Mq::worker($exchange, $queue, function ($message) {
  45. $data = ['id' => implode(',', $message)];
  46. $ok = $this->call('upgrade:wbw.analyses', $data);
  47. if ($ok === 0) {
  48. $this->info('Received count='.count($message).' ok='.$ok);
  49. Log::debug('mq:wbw.analyses done count='.count($message));
  50. } else {
  51. Log::error('mq:wbw.analyses', $data);
  52. }
  53. return $ok;
  54. });
  55. return 0;
  56. }
  57. }