TestMq.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Str;
  5. use App\Http\Api\Mq;
  6. use App\Models\Discussion;
  7. use App\Http\Resources\DiscussionResource;
  8. use App\Models\SentPr;
  9. use App\Http\Resources\SentPrResource;
  10. class TestMq extends Command
  11. {
  12. /**
  13. * The name and signature of the console command.
  14. * php artisan test:mq
  15. * @var string
  16. */
  17. protected $signature = 'test:mq {--discussion=} {--pr=}';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = 'Command description';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return int
  37. */
  38. public function handle()
  39. {
  40. if(\App\Tools\Tools::isStop()){
  41. return 0;
  42. }
  43. Mq::publish('hello',['hello world']);
  44. $discussion = $this->option('discussion');
  45. if($discussion && Str::isUuid($discussion)){
  46. Mq::publish('discussion',new DiscussionResource(Discussion::find($discussion)));
  47. }
  48. $pr = $this->option('pr');
  49. if($pr && Str::isUuid($pr)){
  50. Mq::publish('suggestion',new SentPrResource(SentPr::where('uid',$pr)->first()));
  51. }
  52. return 0;
  53. }
  54. }