<?php
namespace App\Console\Commands;
use App\Jobs\SyncPerusahaanJob;
use App\Models\Karyawan;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
class SyncPerusahaan extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sync:perusahaan {target=karyawan}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$target = $this->argument('target');
if ($target == "karyawan") {
$allKaryawanIds = Karyawan::select('id')->get()->pluck('id')->toArray();
$chunks = array_chunk($allKaryawanIds, 100);
foreach ($chunks as $key => $value) {
dispatch(new SyncPerusahaanJob($value));
}
} else {
$userIds = User::select('id')->get()->pluck('id')->toArray();
$chunks = array_chunk($userIds, 100);
foreach ($chunks as $key => $value) {
dispatch(new SyncPerusahaanJob($value,$target));
}
}
Artisan::call('queue:work --max-time=60 --queue=high,default --stop-when-empty --max-jobs=100');
return 0;
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]