Skip to content

Commit

Permalink
warning on api update stop
Browse files Browse the repository at this point in the history
  • Loading branch information
tomahock committed Jul 8, 2024
1 parent 1913fe1 commit 79a0d4c
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions app/Jobs/ProcessANPCAllDataV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Tools\DiscordTool;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use voku\helper\UTF8;
use GuzzleHttp\Exception\ClientException;

Expand All @@ -32,8 +33,6 @@ public function handle()
{
$url = env('ANEPC_API_URL');



$options = [
'headers' => [
'User-Agent' => 'Fogos.pt/3.0',
Expand Down Expand Up @@ -72,6 +71,31 @@ public function handle()

}
dispatch(new CheckImportantFireIncident());

$currentHash = md5(json_encode($incidents));
$json = file_get_contents('history.json');
$x = json_decode($json,true);

$last = end($x);
$now = Carbon::now();

if($last['hash'] !== $currentHash){
$x[] = [
'hash' => $currentHash,
'time' => $now,
'notify' => false
];
} else {
$then = Carbon::parse($last['time']);
$diff = $then->diffInMinutes($now);
if( $diff >= 10){
DiscordTool::postError('A API não atualiza ha 10 minutos');
$last['notify'] = true;
}
}

file_put_contents('history.json', json_encode($x));

}

private function handleIncidents($data)
Expand Down

0 comments on commit 79a0d4c

Please sign in to comment.