Files
investbrain/app/Jobs/BatchInsertNewCurrencyRatesJob.php
T
2025-04-09 19:25:15 -05:00

42 lines
753 B
PHP

<?php
declare(strict_types=1);
namespace App\Jobs;
use App\Models\CurrencyRate;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
class BatchInsertNewCurrencyRatesJob implements ShouldQueue
{
use Queueable;
/**
* The number of times the job may be attempted.
*/
public $tries = 3;
public int $chunk_size = 100;
public function __construct(
protected array $updates
) {
$this->updates = $updates;
}
/**
* Execute the job.
*/
public function handle(): void
{
$chunks = array_chunk($this->updates, $this->chunk_size);
foreach ($chunks as $chunk) {
CurrencyRate::insertOrIgnore($chunk);
}
}
}