Move DB queries into jobs, so that the scheduler and artisan command calls doesnt evaluate them until the job is actually run
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 35s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s

This commit is contained in:
2024-07-06 19:56:56 +10:00
parent 844d509834
commit 3c7e2bbbc9
3 changed files with 18 additions and 18 deletions

View File

@@ -32,14 +32,14 @@ final class BroadbandTraffic implements ShouldQueue
private const LOGKEY = 'JBT';
protected Model $o; // The supplier we are updating from
protected int $sid; // The supplier we are updating from
private const class_prefix = 'App\Classes\External\Supplier\\';
private const traffic = 'broadband';
public function __construct(Supplier $o)
public function __construct(int $sid)
{
$this->o = $o;
$this->sid = $sid;
}
/**
@@ -50,17 +50,18 @@ final class BroadbandTraffic implements ShouldQueue
*/
public function handle()
{
Log::info(sprintf('%s:Importing Broadband Traffic from [%s]',self::LOGKEY,$this->o->name));
$so = Supplier::findOrFail($this->sid);
Log::info(sprintf('%s:Importing Broadband Traffic from [%s]',self::LOGKEY,$so->name));
if ((! $connection=$this->o->detail->connections->get('broadband')) || (count(array_intersect(array_keys($connection),ExternalSupplier::traffic_connection_keys)) !== 3))
if ((! $connection=$so->detail->connections->get('broadband')) || (count(array_intersect(array_keys($connection),ExternalSupplier::traffic_connection_keys)) !== 3))
throw new \Exception('No or missing connection details for:'.self::traffic);
$u = 0;
// Load our class for this supplier
$class = self::class_prefix.$this->o->name;
$class = self::class_prefix.$so->name;
if (class_exists($class)) {
$o = new $class($this->o);
$o = new $class($so);
} else {
Log::error(sprintf('%s: Class doesnt exist: %s',self::LOGKEY,$class));
@@ -75,7 +76,7 @@ final class BroadbandTraffic implements ShouldQueue
Log::notice(sprintf('%s:Next update is [%s]',self::LOGKEY,$last_update->format('Y-m-d')));
// Delete traffic, since we'll refresh it.
UsageBroadband::where('supplier_id',$this->o->id)
UsageBroadband::where('supplier_id',$so->id)
->where('date',$last_update->format('Y-m-d'))
->delete();
@@ -107,7 +108,7 @@ final class BroadbandTraffic implements ShouldQueue
$to = new UsageBroadband;
$to->date = $last_update;
$to->supplier_id = $this->o->id;
$to->supplier_id = $so->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')];
@@ -139,17 +140,17 @@ final class BroadbandTraffic implements ShouldQueue
Log::info(sprintf('%s: Records Imported [%d] for [%s]',self::LOGKEY,$u,$last_update->format('Y-m-d')));
// Save our current progress.
$this->o->detail->connections = $this->o->detail->connections->put(self::traffic,array_merge($connection,['last'=>$last_update->format('Y-m-d')]));
$this->o->detail->save();
$so->detail->connections = $so->detail->connections->put(self::traffic,array_merge($connection,['last'=>$last_update->format('Y-m-d')]));
$so->detail->save();
// Update our details for the next iteration.
$last_update = $last_update->addDay();
Arr::set($connection,'last',$last_update->format('Y-m-d'));
if ($u) {
if ($this->o->trafficMismatch($date)->count())
if ($so->trafficMismatch($date)->count())
Mail::to('deon@graytech.net.au') // @todo To change
->send(new TrafficMismatch($this->o,$date));
->send(new TrafficMismatch($so,$date));
}
}
}