SendTelegramJob.php 984 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Jobs;
  3. use App\Services\TelegramService;
  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 SendTelegramJob implements ShouldQueue
  10. {
  11. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  12. protected $telegramId;
  13. protected $text;
  14. public $tries = 3;
  15. public $timeout = 5;
  16. /**
  17. * Create a new job instance.
  18. *
  19. * @return void
  20. */
  21. public function __construct(int $telegramId, string $text)
  22. {
  23. $this->onQueue('send_telegram');
  24. $this->telegramId = $telegramId;
  25. $this->text = $text;
  26. }
  27. /**
  28. * Execute the job.
  29. *
  30. * @return void
  31. */
  32. public function handle()
  33. {
  34. $telegramService = new TelegramService();
  35. $telegramService->sendMessage($this->telegramId, $this->text, 'markdown');
  36. }
  37. }