PirepCancelled Event (Cron Expired Pirep Deletion) (#1178)
* PirepCancelled Event (Cron Expired Pirep Deletion) While deleting frozen in progress pireps we should at least send a PirepCancelled event for those who are listening. (or we may have a new PirepDeleted event to be issued in such cases, I think PirepCancelled is enough though) * StyleFix * Another StyleFix * Missing Log Of course it will not be possible to write log entries without the Log itself.
This commit is contained in:
parent
a186bfae2a
commit
f2be14402f
@ -4,9 +4,11 @@ namespace App\Cron\Hourly;
|
|||||||
|
|
||||||
use App\Contracts\Listener;
|
use App\Contracts\Listener;
|
||||||
use App\Events\CronHourly;
|
use App\Events\CronHourly;
|
||||||
|
use App\Events\PirepCancelled;
|
||||||
use App\Models\Enums\PirepState;
|
use App\Models\Enums\PirepState;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove expired live flights
|
* Remove expired live flights
|
||||||
@ -27,8 +29,13 @@ class RemoveExpiredLiveFlights extends Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
$date = Carbon::now('UTC')->subHours(setting('acars.live_time'));
|
$date = Carbon::now('UTC')->subHours(setting('acars.live_time'));
|
||||||
Pirep::where('updated_at', '<', $date)
|
$pireps = Pirep::where('updated_at', '<', $date)
|
||||||
->where('state', PirepState::IN_PROGRESS)
|
->where('state', PirepState::IN_PROGRESS)
|
||||||
->delete();
|
->get();
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user