Move address polling to a Job, better catch Socket connection refused errors

This commit is contained in:
Deon George
2021-09-20 20:39:03 +10:00
parent 8b8b513ed1
commit 82e3283d6d
4 changed files with 86 additions and 41 deletions

View File

@@ -6,9 +6,8 @@ use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Log;
use App\Classes\Protocol\Binkp;
use App\Classes\Sock\SocketClient;
use App\Models\{Address,Setup};
use App\Models\Address;
use App\Jobs\AddressPoll as Job;
class BinkpSend extends Command
{
@@ -29,29 +28,16 @@ class BinkpSend extends Command
/**
* Execute the console command.
*
* @return mixed
* @throws \App\Classes\Sock\SocketException
* @throws \Exception
*/
public function handle()
public function handle(): void
{
Log::info('Call BINKP send');
$no = Address::findFTN($this->argument('ftn'));
if (! $no)
$ao = Address::findFTN($this->argument('ftn'));
if (! $ao)
throw new ModelNotFoundException('Unknown node: '.$this->argument('ftn'));
if ($no->system->mailer_type != Setup::O_BINKP)
throw new \Exception(sprintf('Node [%s] doesnt support BINKD',$this->argument('ftn')));
if ((! $no->system->mailer_address) || (! $no->system->mailer_port))
throw new \Exception(sprintf('Unable to poll [%s] missing mailer details',$this->argument('ftn')));
$client = SocketClient::create($no->system->mailer_address,$no->system->mailer_port);
$o = new Binkp(Setup::findOrFail(config('app.id')));
$o->session(Binkp::SESSION_BINKP,$client,$no);
Log::info(sprintf('Connection ended: %s',$client->address_remote),['m'=>__METHOD__]);
Job::dispatchSync($ao);
}
}

View File

@@ -6,9 +6,8 @@ use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Log;
use App\Classes\Protocol\EMSI;
use App\Classes\Sock\SocketClient;
use App\Models\{Address,Setup};
use App\Models\Address;
use App\Jobs\AddressPoll as Job;
class EMSISend extends Command
{
@@ -29,28 +28,16 @@ class EMSISend extends Command
/**
* Execute the console command.
*
* @return mixed
* @throws \App\Classes\Sock\SocketException
* @throws \Exception
*/
public function handle()
public function handle(): void
{
Log::info('Call EMSI send');
$no = Address::findFTN($this->argument('ftn'));
if (! $no)
$ao = Address::findFTN($this->argument('ftn'));
if (! $ao)
throw new ModelNotFoundException('Unknown node: '.$this->argument('ftn'));
if ($no->system->mailer_type != Setup::O_EMSI)
throw new \Exception(sprintf('Node [%s] doesnt support EMSI',$this->argument('ftn')));
if ((! $no->system->mailer_address) || (! $no->system->mailer_port))
throw new \Exception(sprintf('Unable to poll [%s] missing mailer details',$this->argument('ftn')));
$client = SocketClient::create($no->system->mailer_address,$no->system->mailer_port,38400);
$o = new EMSI(Setup::findOrFail(config('app.id')));
$o->session(EMSI::SESSION_AUTO,$client,$no);
Log::info(sprintf('Connection ended: %s',$client->address_remote),['m'=>__METHOD__]);
Job::dispatchSync($ao);
}
}