Improve node idle detection, including adding NODE_KEEP

This commit is contained in:
Deon George 2024-09-09 20:16:14 +10:00
parent 9d06b422e0
commit eafd203021
2 changed files with 19 additions and 31 deletions

View File

@ -176,41 +176,28 @@ class AddressIdle implements ShouldQueue
$age = Carbon::now()->subDays($days)->endOfDay(); $age = Carbon::now()->subDays($days)->endOfDay();
return Address::select([ return Address::select([
'a.id', 'addresses.id',
'a.system_id', 'system_id',
'a.zone_id', 'zone_id',
'addresses.region_id', 'region_id',
'a.host_id', 'host_id',
'a.node_id', 'node_id',
'a.point_id', 'point_id',
'addresses.active', 'addresses.active',
'addresses.hub_id', 'hub_id',
'addresses.role', 'role',
'addresses.updated_at', '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( ->activeFTN()
Address::UncollectedEchomailTotal()
->union(Address::UncollectedNetmailTotal())
->union(Address::UncollectedFilesTotal()),'a')
->where('systems.active',TRUE) ->where('systems.active',TRUE)
->where('addresses.active',TRUE) ->where(fn($query)=>$query->where('point_id',0)->orWhereNull('point_id'))
->where('zones.active',TRUE) ->whereIn('addresses.id',our_nodes($do)->pluck('id'))
->where('domains.active',TRUE)
->where(fn($query)=>$query->where('a.point_id',0)->orWhereNull('a.point_id'))
->whereNotIn('a.id',our_address()->pluck('id'))
->when($ao,fn($query)=>$query->where('addresses.id',$ao->id)) ->when($ao,fn($query)=>$query->where('addresses.id',$ao->id))
->where('last_session','<',$age) ->where(fn($q)=>$q->where('last_session','<',$age)->orWhereNull('last_session'))
->where('domains.id',$do->id) ->whereRaw(sprintf('((role IS NULL) OR (role=0) OR ((role & %d) > 0))',$flags))
->whereRaw(sprintf('((role IS NULL) OR ((role & %d) > 0))',$flags)) ->whereRaw(sprintf('((role & %d) = 0)',Address::NODE_KEEP))
->join('addresses',['addresses.id'=>'a.id']) ->join('systems',['systems.id'=>'addresses.system_id'])
->join('systems',['systems.id'=>'a.system_id'])
->join('zones',['zones.id'=>'addresses.zone_id'])
->join('domains',['domains.id'=>'zones.domain_id'])
->ftnOrder() ->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']) ->with(['system','zone.domain'])
->dontCache() ->dontCache()
->get(); ->get();

View File

@ -52,9 +52,10 @@ class Address extends Model
public const NODE_HC = 1<<3; // Hub public const NODE_HC = 1<<3; // Hub
public const NODE_NN = 1<<4; // Node public const NODE_NN = 1<<4; // Node
public const NODE_PVT = 1<<5; // Pvt (we dont have address information) @todo 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_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 @todo 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_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_UNKNOWN = 1<<15; // Unknown
public const NODE_ALL = 0x811f; // Mask to catch all nodes, excluding their status public const NODE_ALL = 0x811f; // Mask to catch all nodes, excluding their status