Add a 'paused' state (#1265)

* Add a 'paused' state

* Check paused status
This commit is contained in:
Nabeel S
2021-07-22 11:59:52 -04:00
committed by GitHub
parent f8ded4e410
commit f42a41286d
9 changed files with 20 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Cron\Hourly;
use App\Contracts\Listener;
use App\Events\CronHourly;
use App\Models\Enums\PirepState;
use App\Models\Enums\PirepStatus;
use App\Models\Pirep;
use App\Services\PirepService;
use Carbon\Carbon;
@@ -38,7 +39,10 @@ class DeletePireps extends Listener
protected function deletePireps(int $expire_time_hours, int $state)
{
$dt = Carbon::now('UTC')->subHours($expire_time_hours);
$pireps = Pirep::where('created_at', '<', $dt)->where(['state' => $state])->get();
$pireps = Pirep::where('created_at', '<', $dt)
->where(['state' => $state])
->where(['status', '<>', PirepStatus::PAUSED])
->get();
/** @var PirepService $pirepSvc */
$pirepSvc = app(PirepService::class);

View File

@@ -32,6 +32,7 @@ class RemoveExpiredLiveFlights extends Listener
$pireps = Pirep::where('updated_at', '<', $date)
->where('state', PirepState::IN_PROGRESS)
->get();
foreach ($pireps as $pirep) {
event(new PirepCancelled($pirep));
Log::info('Cron: Deleting Expired Live PIREP id='.$pirep->id.', state='.PirepState::label($pirep->state));

View File

@@ -4,9 +4,6 @@ namespace App\Models\Enums;
use App\Contracts\Enum;
/**
* Class PirepState
*/
class PirepState extends Enum
{
public const IN_PROGRESS = 0; // flight is ongoing
@@ -16,6 +13,7 @@ class PirepState extends Enum
public const DELETED = 4;
public const DRAFT = 5;
public const REJECTED = 6;
public const PAUSED = 7;
protected static $labels = [
self::IN_PROGRESS => 'pireps.state.in_progress',
@@ -25,5 +23,6 @@ class PirepState extends Enum
self::DELETED => 'pireps.state.deleted',
self::DRAFT => 'pireps.state.draft',
self::REJECTED => 'pireps.state.rejected',
self::PAUSED => 'pireps.state.paused',
];
}

View File

@@ -34,6 +34,7 @@ class PirepStatus extends Enum
public const ARRIVED = 'ONB'; // On block
public const CANCELLED = 'DX';
public const EMERG_DESCENT = 'EMG';
public const PAUSED = 'PSD';
protected static $labels = [
self::INITIATED => 'pireps.status.initialized',
@@ -59,5 +60,6 @@ class PirepStatus extends Enum
self::ARRIVED => 'pireps.status.arrived',
self::CANCELLED => 'pireps.status.cancelled',
self::EMERG_DESCENT => 'pireps.status.emerg_decent',
self::PAUSED => 'pireps.status.paused',
];
}