69 lines
1.6 KiB
PHP
69 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Repat\LaravelJobs\Job;
|
|
|
|
use App\Traits\HubStats;
|
|
|
|
class MailSend #implements ShouldQueue
|
|
{
|
|
use HubStats,Dispatchable;
|
|
|
|
private const LOGKEY = 'JMS';
|
|
|
|
/**
|
|
* @param bool $crash Send crash mail only
|
|
*/
|
|
public function __construct(private ?bool $crash=NULL) {}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
// Return the system we poll
|
|
$u = $this
|
|
->HubStats(Carbon::now())
|
|
->get()
|
|
->transform(function($item) {
|
|
if ($x=$item->uplink()) {
|
|
$x->uncollected_echomail = $item->uncollected_echomail;
|
|
$x->uncollected_netmail = $item->uncollected_netmail;
|
|
$x->uncollected_files = $item->uncollected_files;
|
|
|
|
return $x;
|
|
|
|
} else {
|
|
return $item;
|
|
}
|
|
})
|
|
->filter(function($item) {
|
|
if ($item->system->autohold)
|
|
return NULL;
|
|
|
|
return is_null($this->crash) || ($item->system->pollmode) || ($item->system->pollmode === $this->crash) ? $item : NULL;
|
|
});
|
|
|
|
foreach ($u->groupBy('ftn') as $oo) {
|
|
if (Job::where('queue','poll')->get()->pluck('command.address.id')->search(($x=$oo->first())->id) === FALSE) {
|
|
Log::info(sprintf('%s:- Polling [%s] - we have mail for [%d] links. (%d Netmail,%d Echomail,%d Files)',
|
|
self::LOGKEY,
|
|
$x->ftn,
|
|
$oo->count(),
|
|
$oo->sum('uncollected_netmail'),
|
|
$oo->sum('uncollected_echomail'),
|
|
$oo->sum('uncollected_files'),
|
|
));
|
|
|
|
AddressPoll::dispatch($x);
|
|
|
|
} else {
|
|
Log::notice(sprintf('%s:= Not scheduling poll to [%s], there is already one in the queue',self::LOGKEY,$x->ftn));
|
|
}
|
|
}
|
|
}
|
|
} |