dpl/app/Console/Commands/RetryTelegramTickets.php

13 lines
810 B
PHP

<?php
namespace App\Console\Commands;
use App\Jobs\SendTelegramTicketJob;
use App\Models\TelegramTicketMessage;
use Illuminate\Console\Command;
class RetryTelegramTickets extends Command {
protected $signature='telegram:tickets:retry';protected $description='Queue pending ticket notifications without resending uncertain deliveries';
public function handle():int {
TelegramTicketMessage::where('status','sending')->where('updated_at','<',now()->subMinutes(5))->update(['status'=>'unknown','error_code'=>'worker_interrupted']);
TelegramTicketMessage::where('status','pending')->where('created_at','<',now()->subMinute())->where(fn($q)=>$q->whereNull('available_at')->orWhere('available_at','<=',now()))->limit(100)->get()->each(fn($r)=>SendTelegramTicketJob::dispatch($r->id));return self::SUCCESS;
}
}