Skip to content

Commit

Permalink
Merge pull request #280 from nkevins/expired_flight_cleaning
Browse files Browse the repository at this point in the history
Hide expired live flight from live map and remove from DB
  • Loading branch information
nabeelio authored Sep 20, 2018
2 parents c549893 + 075d4b3 commit 61c7a3d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
33 changes: 33 additions & 0 deletions app/Cron/Hourly/RemoveExpiredLiveFlights.php
Original file line number Diff line number Diff line change
@@ -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();
}
}
2 changes: 1 addition & 1 deletion app/Events/CronHourly.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CronHourly
use Dispatchable, SerializesModels;

/**
* CronNightly constructor.
* CronHourly constructor.
*/
public function __construct()
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/AcarsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function checkCancelled(Pirep $pirep)
*/
public function index(Request $request)
{
$pireps = $this->acarsRepo->getPositions();
$pireps = $this->acarsRepo->getPositions(setting('acars.live_time'));
$positions = $this->geoSvc->getFeatureForLiveFlights($pireps);

return response(json_encode($positions), 200, [
Expand Down
1 change: 1 addition & 0 deletions app/Providers/CronServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CronServiceProvider extends ServiceProvider

CronHourly::class => [
\App\Cron\Hourly\RemoveExpiredBids::class,
\App\Cron\Hourly\RemoveExpiredLiveFlights::class,
],
];
}

0 comments on commit 61c7a3d

Please sign in to comment.