From eafd2030214d6b76c75f3789f3b0e5d8c1d87840 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 9 Sep 2024 20:16:14 +1000 Subject: [PATCH] Improve node idle detection, including adding NODE_KEEP --- app/Jobs/AddressIdle.php | 45 ++++++++++++++-------------------------- app/Models/Address.php | 5 +++-- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/app/Jobs/AddressIdle.php b/app/Jobs/AddressIdle.php index e6bf6f1..9f8b80f 100644 --- a/app/Jobs/AddressIdle.php +++ b/app/Jobs/AddressIdle.php @@ -176,41 +176,28 @@ class AddressIdle implements ShouldQueue $age = Carbon::now()->subDays($days)->endOfDay(); return Address::select([ - 'a.id', - 'a.system_id', - 'a.zone_id', - 'addresses.region_id', - 'a.host_id', - 'a.node_id', - 'a.point_id', + 'addresses.id', + 'system_id', + 'zone_id', + 'region_id', + 'host_id', + 'node_id', + 'point_id', 'addresses.active', - 'addresses.hub_id', - 'addresses.role', + 'hub_id', + 'role', 'addresses.updated_at', - DB::raw('sum(a.uncollected_echomail) as uncollected_echomail'), - DB::raw('sum(a.uncollected_netmail) as uncollected_netmail'), - DB::raw('sum(a.uncollected_files) as uncollected_files') ]) - ->from( - Address::UncollectedEchomailTotal() - ->union(Address::UncollectedNetmailTotal()) - ->union(Address::UncollectedFilesTotal()),'a') + ->activeFTN() ->where('systems.active',TRUE) - ->where('addresses.active',TRUE) - ->where('zones.active',TRUE) - ->where('domains.active',TRUE) - ->where(fn($query)=>$query->where('a.point_id',0)->orWhereNull('a.point_id')) - ->whereNotIn('a.id',our_address()->pluck('id')) + ->where(fn($query)=>$query->where('point_id',0)->orWhereNull('point_id')) + ->whereIn('addresses.id',our_nodes($do)->pluck('id')) ->when($ao,fn($query)=>$query->where('addresses.id',$ao->id)) - ->where('last_session','<',$age) - ->where('domains.id',$do->id) - ->whereRaw(sprintf('((role IS NULL) OR ((role & %d) > 0))',$flags)) - ->join('addresses',['addresses.id'=>'a.id']) - ->join('systems',['systems.id'=>'a.system_id']) - ->join('zones',['zones.id'=>'addresses.zone_id']) - ->join('domains',['domains.id'=>'zones.domain_id']) + ->where(fn($q)=>$q->where('last_session','<',$age)->orWhereNull('last_session')) + ->whereRaw(sprintf('((role IS NULL) OR (role=0) OR ((role & %d) > 0))',$flags)) + ->whereRaw(sprintf('((role & %d) = 0)',Address::NODE_KEEP)) + ->join('systems',['systems.id'=>'addresses.system_id']) ->ftnOrder() - ->groupBy('a.system_id','a.id','a.zone_id','addresses.region_id','a.host_id','a.node_id','a.point_id','addresses.hub_id','addresses.role','addresses.active','addresses.updated_at') ->with(['system','zone.domain']) ->dontCache() ->get(); diff --git a/app/Models/Address.php b/app/Models/Address.php index 70c402c..7137df2 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -52,9 +52,10 @@ class Address extends Model public const NODE_HC = 1<<3; // Hub public const NODE_NN = 1<<4; // Node public const NODE_PVT = 1<<5; // Pvt (we dont have address information) @todo - public const NODE_HOLD = 1<<6; // Hold (user has requested hold, we havent heard from the node for 7 days @todo - public const NODE_DOWN = 1<<7; // Down we havent heard from the node for 30 days @todo + public const NODE_HOLD = 1<<6; // Hold (user has requested hold, we havent heard from the node for 7 days + public const NODE_DOWN = 1<<7; // Down we havent heard from the node for 30 days public const NODE_POINT = 1<<8; // Point + public const NODE_KEEP = 1<<9; // Dont mark an address hold/down or de-list automatically public const NODE_UNKNOWN = 1<<15; // Unknown public const NODE_ALL = 0x811f; // Mask to catch all nodes, excluding their status