2018-09-21 02:27:39 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Cron\Hourly;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Listener;
|
2019-07-16 03:51:35 +08:00
|
|
|
use App\Events\CronHourly;
|
2018-09-21 02:27:39 +08:00
|
|
|
use App\Models\Pirep;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove expired live flights
|
|
|
|
*/
|
|
|
|
class RemoveExpiredLiveFlights extends Listener
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Remove expired live flights
|
|
|
|
*
|
|
|
|
* @param CronHourly $event
|
|
|
|
*
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function handle(CronHourly $event): void
|
|
|
|
{
|
|
|
|
if (setting('acars.live_time') === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$date = Carbon::now()->subHours(setting('acars.live_time'));
|
|
|
|
Pirep::whereDate('created_at', '<', $date)
|
|
|
|
->where('state', PirepState::IN_PROGRESS)
|
|
|
|
->delete();
|
|
|
|
}
|
|
|
|
}
|