2022-08-13 08:37:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use App\Helpers\Lock;
|
2022-08-16 10:44:16 +00:00
|
|
|
use App\Models\Host;
|
2022-08-13 08:37:17 +00:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
2022-08-16 10:44:16 +00:00
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2022-08-13 08:37:17 +00:00
|
|
|
|
|
|
|
class HostCost implements ShouldQueue
|
|
|
|
{
|
2022-09-08 16:12:02 +00:00
|
|
|
use InteractsWithQueue, Queueable, SerializesModels, Lock;
|
2022-08-13 08:37:17 +00:00
|
|
|
|
|
|
|
public $cache_key, $cache, $user;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2022-08-23 09:36:10 +00:00
|
|
|
// $this->cache = new Cache();
|
2022-08-15 13:20:42 +00:00
|
|
|
|
2022-08-13 08:37:17 +00:00
|
|
|
// chunk hosts and load user
|
2022-10-29 03:24:37 +00:00
|
|
|
Host::active()->with('user')->chunk(1000, function ($hosts) {
|
2022-08-13 08:37:17 +00:00
|
|
|
foreach ($hosts as $host) {
|
2022-08-23 09:36:10 +00:00
|
|
|
$host->cost();
|
2022-08-13 08:37:17 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|