ServerLogJob.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Jobs;
  3. use App\Services\ServerService;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. class ServerLogJob implements ShouldQueue
  10. {
  11. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  12. protected $u;
  13. protected $d;
  14. protected $userId;
  15. protected $server;
  16. protected $protocol;
  17. public $tries = 3;
  18. public $timeout = 3;
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct($u, $d, $userId, $server, $protocol)
  25. {
  26. $this->onQueue('server_log');
  27. $this->u = $u;
  28. $this->d = $d;
  29. $this->userId = $userId;
  30. $this->server = $server;
  31. $this->protocol = $protocol;
  32. }
  33. /**
  34. * Execute the job.
  35. *
  36. * @return void
  37. */
  38. public function handle()
  39. {
  40. $serverService = new ServerService();
  41. if (!$serverService->log(
  42. $this->userId,
  43. $this->server->id,
  44. $this->u,
  45. $this->d,
  46. $this->server->rate,
  47. $this->protocol
  48. )) {
  49. throw new \Exception('日志记录失败');
  50. }
  51. }
  52. }