Minor job cleanup, import Ezypay payments update

This commit is contained in:
Deon George
2021-07-29 13:11:14 +10:00
parent 10e6c73b2b
commit 00f215b780
6 changed files with 134 additions and 123 deletions

View File

@@ -5,18 +5,18 @@ namespace App\Jobs;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use App\Mail\TrafficMismatch;
use App\Models\Service\Adsl;
use App\Models\Service\AdslTraffic;
use App\Models\AdslSupplier;
use Illuminate\Support\Facades\Mail;
/**
* Class BroadbandTraffic
@@ -24,18 +24,18 @@ use Illuminate\Support\Facades\Mail;
*
* @package App\Jobs
*/
class BroadbandTraffic implements ShouldQueue
final class BroadbandTraffic implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private const LOGKEY = 'JBT';
protected $aso = NULL; // The supplier we are updating from
private $class_prefix = 'App\Classes\External\Supplier\\';
protected Model $o; // The supplier we are updating from
private const class_prefix = 'App\Classes\External\Supplier\\';
public function __construct(AdslSupplier $o)
{
$this->aso = $o;
$this->o = $o;
}
/**
@@ -47,14 +47,14 @@ class BroadbandTraffic implements ShouldQueue
*/
public function handle()
{
Log::info(sprintf('%s:Importing Broadband Traffic from [%s]',self::LOGKEY,$this->aso->name),['m'=>__METHOD__]);
Log::info(sprintf('%s:Importing Broadband Traffic from [%s]',self::LOGKEY,$this->o->name));
$u = 0;
// Load our class for this supplier
$class = $this->class_prefix.$this->aso->name;
$class = self::class_prefix.$this->o->name;
if (class_exists($class)) {
$o = new $class($this->aso);
$o = new $class($this->o);
} else {
Log::error(sprintf('%s: Class doesnt exist: %d',get_class($this),$class));
@@ -62,12 +62,12 @@ class BroadbandTraffic implements ShouldQueue
}
// Repeat pull traffic data until yesterday
while ($this->aso->stats_lastupdate < Carbon::now()->subDay()) {
Log::notice(sprintf('%s:Next update is [%s]',self::LOGKEY,$this->aso->stats_lastupdate->format('Y-m-d')),['m'=>__METHOD__]);
while ($this->o->stats_lastupdate < Carbon::now()->subDay()) {
Log::notice(sprintf('%s:Next update is [%s]',self::LOGKEY,$this->o->stats_lastupdate->format('Y-m-d')));
// Delete traffic, since we'll refresh it.
AdslTraffic::where('supplier_id',$this->aso->id)
->where('date',$this->aso->stats_lastupdate)
AdslTraffic::where('supplier_id',$this->o->id)
->where('date',$this->o->stats_lastupdate)
->delete();
$c = 0;
@@ -100,8 +100,8 @@ class BroadbandTraffic implements ShouldQueue
$to = new AdslTraffic;
$to->site_id = 1; // @todo TO ADDRESS
$to->date = $this->aso->stats_lastupdate;
$to->supplier_id = $this->aso->id;
$to->date = $this->o->stats_lastupdate;
$to->supplier_id = $this->o->id;
$to->up_peak = $row[$o->getColumnKey('Peak upload')];
$to->up_offpeak = $row[$o->getColumnKey('Off peak upload')];
$to->down_peak = $row[$o->getColumnKey('Peak download')];
@@ -112,7 +112,7 @@ class BroadbandTraffic implements ShouldQueue
// If we have no records
if ($oo->count() != 1) {
Log::error(sprintf('%s:Too many services return for [%s]',self::LOGKEY,$row[$o->getColumnKey('Login')]),['m'=>__METHOD__,'date'=>$date,'count'=>$oo->count()]);
Log::error(sprintf('%s:Too many services return for [%s]',self::LOGKEY,$row[$o->getColumnKey('Login')]),['date'=>$date,'count'=>$oo->count()]);
$to->service = $row[$o->getColumnKey('Login')];
$to->save();
@@ -124,20 +124,20 @@ class BroadbandTraffic implements ShouldQueue
$u++;
} catch (\Exception $e) {
Log::error(sprintf('%s:Exception occurred when storing traffic record for [%s].',self::LOGKEY,$row[$o->getColumnKey('Login')]),['m'=>__METHOD__,'row'=>$row,'line'=>$line]);
Log::error(sprintf('%s:Exception occurred when storing traffic record for [%s].',self::LOGKEY,$row[$o->getColumnKey('Login')]),['row'=>$row,'line'=>$line]);
throw new \Exception('Error while storing traffic date');
}
}
Log::info(sprintf('%s: Records Imported [%d] for [%s]',self::LOGKEY,$u,$this->aso->stats_lastupdate->format('Y-m-d')),['m'=>__METHOD__]);
Log::info(sprintf('%s: Records Imported [%d] for [%s]',self::LOGKEY,$u,$this->o->stats_lastupdate->format('Y-m-d')));
if ($u) {
$this->aso->stats_lastupdate = $this->aso->stats_lastupdate->addDay();
$this->aso->save();
$this->o->stats_lastupdate = $this->o->stats_lastupdate->addDay();
$this->o->save();
if ($this->aso->trafficMismatch($date)->count())
if ($this->o->trafficMismatch($date)->count())
Mail::to('deon@graytech.net.au') // @todo To change
->send(new TrafficMismatch($this->aso,$date));
->send(new TrafficMismatch($this->o,$date));
}
}
}