Hide expired live flight from live map and remove from DB

This commit is contained in:
Kevin
2018-09-21 02:27:39 +08:00
parent e878168d4c
commit d40c9ba91f
4 changed files with 36 additions and 2 deletions
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace App\Cron\Hourly;
use App\Events\CronHourly;
use App\Interfaces\Listener;
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();
}
}