Skip to content

Commit

Permalink
cleanup icnf fires
Browse files Browse the repository at this point in the history
  • Loading branch information
tomahock committed Jul 9, 2024
1 parent 6f100a8 commit 3abf1fe
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
2 changes: 2 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console;

use App\Jobs\CleanICNFFires;
use App\Jobs\DailySummary;
use App\Jobs\HandleANEPCImportantData;
use App\Jobs\HandleANEPCPositEmail;
Expand Down Expand Up @@ -68,6 +69,7 @@ protected function schedule(Schedule $schedule)
$schedule->job(new DailySummary())->daily()->at('09:30');

$schedule->job(new ProcessICNFNewFireData())->everyFiveMinutes();
$schedule->job(new CleanICNFFires())->everyFiveMinutes();

//$schedule->job(new HandleANEPCImportantData())->everyTenMinutes();
//$schedule->job(new HandleANEPCPositEmail())->everyTenMinutes();
Expand Down
39 changes: 39 additions & 0 deletions app/Jobs/CleanICNFFires.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Jobs;

use App\Models\Incident;
use Carbon\Carbon;

class CleanICNFFires extends Job
{
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$incidents = Incident::where('active', true)->get();
$now = Carbon::now();
foreach ($incidents as $incident){
if($incident->status === 'Em Resolução'){
$diff = $incident->created->diffInMinutes($now);
if($diff > 60){
$incident->active = false;
}
}
}

}
}
5 changes: 3 additions & 2 deletions app/Jobs/ProcessANPCAllDataV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ public function handle()
$x[] = [
'hash' => $currentHash,
'time' => $now,
'ticks' => 0,
'ticks' => 1,
'notify' => false
];

if($last['notify']){
DiscordTool::postError('Voltou a API depois de ' . $diff . ' minutos sem atualizar');
$last['ticks'] = 0;
}
} else {
if( $diff >= 10){
Expand All @@ -100,7 +101,7 @@ public function handle()
}
}

if($last['ticks'] % 5 === 0){
if($last['ticks'] % 5 == 0){
DiscordTool::postError('A API não atualiza ha '.$diff.' minutos');
}

Expand Down
19 changes: 14 additions & 5 deletions app/Jobs/ProcessICNFNewFireData.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public function handle()

preg_match_all('/\[(.*?)\]/', $data, $result);

print_r($result);

$i = 0;
foreach ($result[1] as $r) {
if ($i === 0 || $i === 1) {
Expand All @@ -51,11 +53,18 @@ public function handle()
++$i;

$rr = explode("',", $r);
if(isset($rr[12]) && $rr[12] = "'Extinto"){
$status = 'Em Resolução';
$statusCode = 7;
$statusColor = '65C4ED';
} else {
$status = 'Em Curso';
$statusCode = 5;
$statusColor = 'B81E1F';
}

$id = strip_tags(str_replace("'", '', $rr[0]));

Log::debug('id => ' . $id);

$this->incident = Incident::where('id', $id)
->get();

Expand Down Expand Up @@ -88,9 +97,9 @@ public function handle()
'coordinates' => [(float) $d->LAT->__toString(), (float) $d->LON->__toString()],
'naturezaCode' => '3103',
'natureza' => 'Mato',
'statusCode' => 3,
'statusColor' =>'CE773C',
'status' => 'Despacho',
'statusCode' => $statusCode,
'statusColor' =>$statusColor,
'status' => $status,
'localidade' => $localidade,
'active' => true,
'sadoId' => $id,
Expand Down

0 comments on commit 3abf1fe

Please sign in to comment.