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;
|
2021-05-10 06:30:50 +08:00
|
|
|
use App\Events\PirepCancelled;
|
2020-02-09 02:29:34 +08:00
|
|
|
use App\Models\Enums\PirepState;
|
2022-03-07 22:55:30 +08:00
|
|
|
use App\Models\Enums\PirepStatus;
|
2018-09-21 02:27:39 +08:00
|
|
|
use App\Models\Pirep;
|
|
|
|
use Carbon\Carbon;
|
2021-05-10 06:30:50 +08:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2018-09-21 02:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove expired live flights
|
|
|
|
*/
|
|
|
|
class RemoveExpiredLiveFlights extends Listener
|
|
|
|
{
|
|
|
|
/**
|
2020-02-09 02:29:34 +08:00
|
|
|
* Remove expired live flights that haven't had an update in the live time
|
2018-09-21 02:27:39 +08:00
|
|
|
*
|
|
|
|
* @param CronHourly $event
|
|
|
|
*
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function handle(CronHourly $event): void
|
|
|
|
{
|
|
|
|
if (setting('acars.live_time') === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-13 21:25:38 +08:00
|
|
|
$date = Carbon::now('UTC')->subHours(setting('acars.live_time'));
|
2021-05-10 06:30:50 +08:00
|
|
|
$pireps = Pirep::where('updated_at', '<', $date)
|
2018-09-21 02:27:39 +08:00
|
|
|
->where('state', PirepState::IN_PROGRESS)
|
2022-03-07 22:55:30 +08:00
|
|
|
->where('status', '<>', PirepStatus::PAUSED)
|
2021-05-10 06:30:50 +08:00
|
|
|
->get();
|
2021-07-22 23:59:52 +08:00
|
|
|
|
2021-05-10 06:30:50 +08:00
|
|
|
foreach ($pireps as $pirep) {
|
|
|
|
event(new PirepCancelled($pirep));
|
|
|
|
Log::info('Cron: Deleting Expired Live PIREP id='.$pirep->id.', state='.PirepState::label($pirep->state));
|
|
|
|
$pirep->delete();
|
|
|
|
}
|
2018-09-21 02:27:39 +08:00
|
|
|
}
|
|
|
|
}
|