Skip to content

Commit ab62005

Browse files
committed
feat: Add dynamic timeout for SendJob job
1 parent c4ebb15 commit ab62005

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/SendJob.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function __construct(
2626
private string $chatId,
2727
private string|null $topicId = null,
2828
private string|null $proxy = null,
29+
private int $timeout = 5,
2930
)
3031
{
3132
}
@@ -39,7 +40,7 @@ public function handle(): void
3940
$httpClientOption['proxy'] = $this->proxy;
4041
}
4142

42-
$httpClientOption['timeout'] = 5;
43+
$httpClientOption['timeout'] = $this->timeout;
4344

4445
$params = [
4546
'text' => $this->message,

src/TelegramBotHandler.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ class TelegramBotHandler extends AbstractProcessingHandler
5252

5353
protected TopicDetector $topicDetector;
5454

55+
/**
56+
* Timeout for Telegram API requests in seconds.
57+
*
58+
* @var int
59+
*/
60+
protected int $timeout;
61+
5562
/**
5663
* @param string $token Telegram bot access token provided by BotFather
5764
* @param string $channel Telegram channel name
@@ -66,7 +73,9 @@ public function __construct(
6673
$level = Logger::DEBUG,
6774
bool $bubble = true,
6875
string $bot_api = 'https://api.telegram.org/bot',
69-
string|null $proxy = null)
76+
string|null $proxy = null,
77+
int $timeout = 5
78+
)
7079
{
7180
parent::__construct($level, $bubble);
7281

@@ -78,6 +87,7 @@ public function __construct(
7887
$this->level = $level;
7988
$this->bubble = $bubble;
8089
$this->proxy = $proxy;
90+
$this->timeout = $timeout;
8191

8292
$this->topicDetector = new TopicDetector($topics_level);
8393
}
@@ -127,9 +137,9 @@ protected function send(string $message, $token = null, $chatId = null, $topicId
127137
$message = $this->truncateTextToTelegramLimit($message);
128138

129139
if (empty($this->queue)) {
130-
dispatch_sync(new SendJob($url, $message, $chatId, $topicId, $this->proxy));
140+
dispatch_sync(new SendJob($url, $message, $chatId, $topicId, $this->proxy, $this->timeout));
131141
} else {
132-
dispatch(new SendJob($url, $message, $chatId, $topicId, $this->proxy))->onQueue($this->queue);
142+
dispatch(new SendJob($url, $message, $chatId, $topicId, $this->proxy, $this->timeout))->onQueue($this->queue);
133143
}
134144
}
135145

0 commit comments

Comments
 (0)