fix: log
This commit is contained in:
@@ -3,16 +3,19 @@
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Services\TelegramNotifier;
|
||||
use App\Support\SafeLog;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
|
||||
class SendTelegramMessage implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public int $tries = 3;
|
||||
public int $tries = 4;
|
||||
|
||||
public int $timeout = 20;
|
||||
public int $timeout = 25;
|
||||
|
||||
public function __construct(
|
||||
public string $chatId,
|
||||
@@ -20,15 +23,38 @@ class SendTelegramMessage implements ShouldQueue
|
||||
public ?string $token = null,
|
||||
) {}
|
||||
|
||||
/** @return list<int> */
|
||||
public function backoff(): array
|
||||
{
|
||||
return [10, 60, 300];
|
||||
}
|
||||
|
||||
public function handle(TelegramNotifier $telegram): void
|
||||
{
|
||||
$result = $telegram->sendToChat($this->chatId, $this->text, $this->token);
|
||||
if (! $result['ok']) {
|
||||
\App\Support\SafeLog::channel('telegram')->warning('SendTelegramMessage job failed', [
|
||||
'chat_id' => $this->chatId,
|
||||
'error' => $result['error'] ?? 'unknown',
|
||||
'text_preview' => mb_substr($this->text, 0, 80),
|
||||
]);
|
||||
if ($result['ok']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$error = (string) ($result['error'] ?? 'unknown');
|
||||
SafeLog::channel('telegram')->warning('SendTelegramMessage job failed', [
|
||||
'chat_id' => $this->chatId,
|
||||
'error' => $error,
|
||||
'text_preview' => mb_substr($this->text, 0, 80),
|
||||
'retryable' => TelegramNotifier::isRetryableSendError($error),
|
||||
]);
|
||||
|
||||
if (TelegramNotifier::isRetryableSendError($error)) {
|
||||
throw new RuntimeException('telegram send failed: '.$error);
|
||||
}
|
||||
}
|
||||
|
||||
public function failed(?Throwable $e): void
|
||||
{
|
||||
SafeLog::channel('telegram')->error('SendTelegramMessage given up after retries', [
|
||||
'chat_id' => $this->chatId,
|
||||
'error' => $e?->getMessage(),
|
||||
'text_preview' => mb_substr($this->text, 0, 80),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user