Continue to show all common addresses in Items Waiting tab, Add Address Clear Queue job to delete anything in the queue for an address
This commit is contained in:
parent
80fa3e840b
commit
0bd2f6e82c
42
app/Console/Commands/AddressClearQueue.php
Normal file
42
app/Console/Commands/AddressClearQueue.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use App\Jobs\AddressClearQueue as Job;
|
||||
use App\Models\Address;
|
||||
|
||||
class AddressClearQueue extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'address:clear:queue'
|
||||
.' {ftn : FTN}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Clear up anything queued for an FTN';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$ao = Address::findFTN($this->argument('ftn'),TRUE,TRUE);
|
||||
|
||||
if (! $ao) {
|
||||
$this->error('FTN not found: '.$this->argument('ftn'));
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
return Job::dispatchSync($ao);
|
||||
}
|
||||
}
|
67
app/Jobs/AddressClearQueue.php
Normal file
67
app/Jobs/AddressClearQueue.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
use App\Classes\FTN\Message;
|
||||
use App\Models\{Address,Domain,System};
|
||||
use App\Notifications\Echomails\AbsentNodes;
|
||||
use App\Notifications\Emails\NodeMarkedDown as NodeMarkedDownEmail;
|
||||
use App\Notifications\Netmails\NodeMarkedDown as NodeMarkedDownNetmail;
|
||||
use App\Notifications\Emails\NodeMarkedHold as NodeMarkedHoldEmail;
|
||||
use App\Notifications\Netmails\NodeMarkedHold as NodeMarkedHoldNetmail;
|
||||
use App\Notifications\Emails\NodeDelisted as NodeDelistedEmail;
|
||||
use App\Notifications\Netmails\NodeDelisted as NodeDelistedNetmail;
|
||||
|
||||
class AddressClearQueue implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
private const LOGKEY = 'JAC';
|
||||
|
||||
private Address $ao; // System address
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(Address $ao)
|
||||
{
|
||||
$this->ao = $ao->withoutRelations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
// Remove echomail not collected from echomail_seenby
|
||||
DB::table('echomail_seenby')
|
||||
->where('address_id',$this->ao->id)
|
||||
->whereNotNull('export_at')
|
||||
->whereNull('sent_at')
|
||||
->delete();
|
||||
|
||||
// Remove FLAG_INTRANSIT from netmail that hasnt been delivered
|
||||
DB::table('netmails')
|
||||
->where('tftn_id',$this->ao->id)
|
||||
->whereRaw(sprintf('(flags & %d) > 0',Message::FLAG_INTRANSIT))
|
||||
->update(['flags'=>DB::raw(sprintf('(flags & ~%d)',Message::FLAG_INTRANSIT))]);
|
||||
|
||||
// Remove files not collected
|
||||
DB::table('file_seenby')
|
||||
->where('address_id',$this->ao->id)
|
||||
->whereNotNull('export_at')
|
||||
->whereNull('sent_at')
|
||||
->delete();
|
||||
}
|
||||
}
|
@ -67,26 +67,6 @@ class AddressIdle implements ShouldQueue
|
||||
Log::info(sprintf('%s:- Delisting [%s], not seen for at least [%d] days',self::LOGKEY,$ao->ftn,$ao->system->last_seen?->diffInDays()));
|
||||
$contact = FALSE;
|
||||
|
||||
// Remove echomail not collected from echomail_seenby
|
||||
DB::table('echomail_seenby')
|
||||
->where('address_id',$ao->id)
|
||||
->whereNotNull('export_at')
|
||||
->whereNull('sent_at')
|
||||
->delete();
|
||||
|
||||
// Remove FLAG_INTRANSIT from netmail that hasnt been delivered
|
||||
DB::table('netmails')
|
||||
->where('tftn_id',$ao->id)
|
||||
->whereRaw(sprintf('(flags & %d) > 0',Message::FLAG_INTRANSIT))
|
||||
->update(['flags'=>DB::raw(sprintf('(flags & ~%d)',Message::FLAG_INTRANSIT))]);
|
||||
|
||||
// Remove files not collected
|
||||
DB::table('file_seenby')
|
||||
->where('address_id',$ao->id)
|
||||
->whereNotNull('export_at')
|
||||
->whereNull('sent_at')
|
||||
->delete();
|
||||
|
||||
// Remove subscribed echoareas
|
||||
$ao->echoareas()->detach();
|
||||
|
||||
@ -97,6 +77,9 @@ class AddressIdle implements ShouldQueue
|
||||
$ao->validated = FALSE;
|
||||
$ao->save();
|
||||
|
||||
// Clear the queue
|
||||
AddressClearQueue::dispatchSync($ao);
|
||||
|
||||
// Email Alert
|
||||
if ($ao->system->users->count()) {
|
||||
Notification::send($ao->system->users,new NodeDelistedEmail($ao->withoutRelations()));
|
||||
|
@ -24,19 +24,28 @@ use App\Traits\{QueryCacheableConfig,ScopeActive};
|
||||
*
|
||||
* If an address is validated, we know that the system is using the address (we've confirmed that during a session).
|
||||
* validated is update/removed is during a mailer session, confirming if the node has the address
|
||||
* @todo Remove validated, if that system hasnt used the address for a defined period (eg: 30)
|
||||
*
|
||||
* We'll only trigger a poll to a system that we have mail for if active && validated, unless "forced".
|
||||
*
|
||||
* Any mail for that address will be delivered, if active && validated.
|
||||
*
|
||||
* Address status:
|
||||
* + Active (active=true/validated=true) - mail can flow and in one of our networks (we have session details)
|
||||
* + Pending (active=true/validated=false) - remote hasnt configured address during a session and in one of our networks
|
||||
* + Known (active=true/validated=true) - the node presented this address, but we didnt auth it, and its a network we are not in
|
||||
* + Unconfirm (active=true/validated=true) - the node presented this address, but we dont manage the address (it uses a different hub)
|
||||
* + Nodelist (active=true/validated=true) - the node presented this address, but we dont manage the address and its in a recent nodelist
|
||||
* + Delisted (active=false/validated=true) - this node shouldnt use this address any more
|
||||
* + Freed (active=false/validated=false) - this node shouldnt is known to not be using this address any more
|
||||
*
|
||||
* Other Status
|
||||
* + citizen - The address belongs to one of our jurisdiction (hub_id = our address, NC,RC,ZC)
|
||||
* + foreign - The address doesnt belong to our jurisdiction
|
||||
*
|
||||
* @see \App\Http\Requests\AddressAdd::class for rules about AKA and role
|
||||
*/
|
||||
|
||||
// Need to add
|
||||
// Calculated Region for an FTN, ie: find the parent and use their region id
|
||||
// - if creating an RC, then the region is part of the creation, ZC region is 0
|
||||
// Then use this in createFTN
|
||||
|
||||
class Address extends Model
|
||||
{
|
||||
use QueryCacheableConfig,ScopeActive,SoftDeletes;
|
||||
@ -246,7 +255,7 @@ class Address extends Model
|
||||
$o = self::findZone($do,$ftn['n'],$ftn['f'],$ftn['p'],$trashed);
|
||||
}
|
||||
|
||||
return ($o && $o->system->active) ? $o : NULL;
|
||||
return ($o && ($trashed || $o->system->active)) ? $o : NULL;
|
||||
}
|
||||
|
||||
public static function newFTN(string $address): self
|
||||
@ -414,7 +423,7 @@ class Address extends Model
|
||||
public function scopeFTN($query)
|
||||
{
|
||||
return $query
|
||||
->select(['addresses.id','region_id','host_id','node_id','point_id','addresses.zone_id','addresses.active','role','security','addresses.system_id','addresses.active','validated'])
|
||||
->select(['addresses.id','region_id','host_id','node_id','point_id','addresses.zone_id','addresses.active','role','security','addresses.system_id','addresses.active','validated','deleted_at'])
|
||||
->join('zones',['zones.id'=>'addresses.zone_id'])
|
||||
->join('domains',['domains.id'=>'zones.domain_id'])
|
||||
->orderBy('domains.name')
|
||||
|
@ -200,6 +200,14 @@ class System extends Model
|
||||
|
||||
/* METHODS */
|
||||
|
||||
public function addresses_common(): Collection
|
||||
{
|
||||
$our = our_address()->pluck('zone.domain_id')->unique();
|
||||
|
||||
// Return our akas, filter with our_addresses()
|
||||
return $this->addresses->filter(fn($item)=>$our->contains($item->zone->domain_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ACTIVE addresses that are common with our addresses
|
||||
*
|
||||
|
@ -125,7 +125,7 @@
|
||||
<tbody>
|
||||
@foreach ($o->addresses as $oo)
|
||||
<tr>
|
||||
<td @if($oo->trashed()) class="trashed" @elseif (! $oo->active) class="inactive" @endif>{{ $oo->ftn }}<span class="float-end"><data value="{{ $oo->id }}:{{ $oo->validated ? 1 : 0 }}" class="validated"><i title="@if($oo->validated)Mail flowing @else Mail held @endif" @class(['bi','bi-activity'=>$oo->validated,'bi-radioactive'=>(! $oo->validated)])></i></data></span></td>
|
||||
<td @class(['trashed'=>$oo->trashed(),'inactive'=>(! $oo->trashed()) && (! $oo->active)])>{{ $oo->ftn }}<span class="float-end"><data value="{{ $oo->id }}:{{ $oo->validated ? 1 : 0 }}" class="validated"><i title="@if($oo->validated)Mail flowing @else Mail held @endif" @class(['bi','bi-activity'=>$oo->validated,'bi-radioactive'=>(! $oo->validated)])></i></data></span></td>
|
||||
<td>{{ $oo->active ? 'YES' : 'NO' }}</td>
|
||||
<td class="text-end">{{ $oo->security }}</td>
|
||||
<td>{{ $oo->role_name }}</td>
|
||||
@ -320,10 +320,10 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@foreach ($o->aka_common() as $ao)
|
||||
@foreach ($o->addresses_common() as $ao)
|
||||
<tr>
|
||||
<td>{{ $ao->ftn }}</td>
|
||||
<td>{{ $ao->netmailWaiting()->count() }}</td>
|
||||
<td @class(['trashed'=>$ao->trashed(),'inactive'=>(! $ao->trashed()) && (! $ao->active)])>{{ $ao->ftn }}</td>
|
||||
<td class="text-end">{{ $ao->netmailWaiting()->count() }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
@ -342,10 +342,10 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@foreach ($o->aka_common() as $ao)
|
||||
@foreach ($o->addresses_common() as $ao)
|
||||
<tr>
|
||||
<td>{{ $ao->ftn }}</td>
|
||||
<td>{{ $ao->echomailWaiting()->count() }}</td>
|
||||
<td @class(['trashed'=>$ao->trashed(),'inactive'=>(! $ao->trashed()) && (! $ao->active)])>{{ $ao->ftn }}</td>
|
||||
<td class="text-end">{{ $ao->echomailWaiting()->count() }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
@ -364,10 +364,10 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@foreach ($o->aka_common() as $ao)
|
||||
@foreach ($o->addresses_common() as $ao)
|
||||
<tr>
|
||||
<td>{{ $ao->ftn }}</td>
|
||||
<td>{{ $ao->filesWaiting()->count() }}</td>
|
||||
<td @class(['trashed'=>$ao->trashed(),'inactive'=>(! $ao->trashed()) && (! $ao->active)])>{{ $ao->ftn }}</td>
|
||||
<td class="text-end">{{ $ao->filesWaiting()->count() }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
|
Loading…
Reference in New Issue
Block a user