Hide expired live flight from live map and remove from DB
This commit is contained in:
parent
e878168d4c
commit
d40c9ba91f
33
app/Cron/Hourly/RemoveExpiredLiveFlights
Normal file
33
app/Cron/Hourly/RemoveExpiredLiveFlights
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,7 @@ class CronHourly
|
|||||||
use Dispatchable, SerializesModels;
|
use Dispatchable, SerializesModels;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CronNightly constructor.
|
* CronHourly constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -69,7 +69,7 @@ class AcarsController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$pireps = $this->acarsRepo->getPositions();
|
$pireps = $this->acarsRepo->getPositions(setting('acars.live_time'));
|
||||||
$positions = $this->geoSvc->getFeatureForLiveFlights($pireps);
|
$positions = $this->geoSvc->getFeatureForLiveFlights($pireps);
|
||||||
|
|
||||||
return response(json_encode($positions), 200, [
|
return response(json_encode($positions), 200, [
|
||||||
|
@ -36,6 +36,7 @@ class CronServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
CronHourly::class => [
|
CronHourly::class => [
|
||||||
\App\Cron\Hourly\RemoveExpiredBids::class,
|
\App\Cron\Hourly\RemoveExpiredBids::class,
|
||||||
|
\App\Cron\Hourly\RemoveExpiredLiveFlights::class,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user