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();
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();

View File

@ -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