Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide expired live flight from live map and remove from DB #280

Merged
merged 2 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
],
];
}