From aa55d05ccb3a96a3629a8d37524fe18ea101944d Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 9 Dec 2024 12:03:38 +1100 Subject: [PATCH] Change our_nodes() to include only active zones/domains also. Updates to heartbeat --- app/Jobs/SystemHeartbeat.php | 35 +++++------------------------------ app/Models/User.php | 3 +-- app/helpers.php | 5 +++-- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/app/Jobs/SystemHeartbeat.php b/app/Jobs/SystemHeartbeat.php index ce5955e..813054b 100644 --- a/app/Jobs/SystemHeartbeat.php +++ b/app/Jobs/SystemHeartbeat.php @@ -7,7 +7,7 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Support\Facades\Log; use Repat\LaravelJobs\Job; -use App\Models\{Address,Setup}; +use App\Models\Address; class SystemHeartbeat #implements ShouldQueue { @@ -25,37 +25,12 @@ class SystemHeartbeat #implements ShouldQueue */ public function handle(): void { - // Our zones - $our_zones = our_address()->pluck('zone_id')->unique(); - // Find our uplinks that are hubs, NC, RC or ZCs // Find any system that also has heartbeat configured - $l = Address::select(['addresses.id','addresses.zone_id','addresses.region_id','addresses.host_id','addresses.node_id','addresses.point_id','role','addresses.system_id']) - ->distinct('systems.id') - ->join('systems',['systems.id'=>'addresses.system_id']) - ->join('system_zone',['system_zone.system_id'=>'systems.id']) - ->join('zones',['zones.id'=>'addresses.zone_id']) - ->join('domains',['domains.id'=>'zones.domain_id']) - ->where('systems.active',true) - ->where('addresses.active',TRUE) - ->where('zones.active',TRUE) - ->where('domains.active',TRUE) - ->whereIN('addresses.zone_id',$our_zones) - ->whereNotNull('pollmode') - ->where(function($query) { - return $query - ->where('role','<',Address::NODE_NN) - ->orWhereNotNull('heartbeat'); - }) - ->when(! $this->force,function($query) { - return $query - ->where(function($query) { - return $query->whereNull('autohold') - ->orWhere('autohold',FALSE); - }); - }) - ->with(['system','zone.domain']) - ->get(); + $l = our_nodes() + ->filter(fn($item)=>$item->heartbeat || ($item->role_id < Address::NODE_NN)) + ->filter(fn($item)=>$this->force || (! $item->autohold)) + ->unique(fn($item)=>$item->system_id); // If we havent polled in heatbeat hours, poll system foreach ($l as $oo) { diff --git a/app/Models/User.php b/app/Models/User.php index 8edccdb..3009f0a 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -77,13 +77,12 @@ class User extends Authenticatable implements MustVerifyEmail public function addresses(): Collection { - return Address::select('addresses.*') + return Address::FTN() ->join('systems',['systems.id'=>'addresses.system_id']) ->join('system_user',['system_user.system_id'=>'systems.id']) ->where('system_user.user_id',$this->id) ->where('systems.active',TRUE) ->ActiveFTN() - ->FTN() ->get(); } diff --git a/app/helpers.php b/app/helpers.php index fbfb368..d0f7482 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -179,11 +179,12 @@ function our_nodes(Domain $do=NULL): Collection { return Address::select(['addresses.id','addresses.zone_id','region_id','host_id','node_id','point_id','addresses.system_id','role']) ->join('system_zone',['system_zone.system_id'=>'addresses.system_id','system_zone.zone_id'=>'addresses.zone_id']) + ->join('zones',['zones.id'=>'system_zone.zone_id']) + ->join('domains',['domains.id'=>'zones.domain_id']) ->when(! is_null($do), fn($query)=>$query - ->join('zones',['zones.id'=>'addresses.zone_id']) ->where('domain_id',$do->id)) - ->active() + ->ActiveFTN() ->FTNorder() ->get(); }