Skip to content

Instantly share code, notes, and snippets.

@shreyanshp-cactus
Last active February 5, 2025 07:20
Show Gist options
  • Select an option

  • Save shreyanshp-cactus/a2c6975a160be97c000c93b480183deb to your computer and use it in GitHub Desktop.

Select an option

Save shreyanshp-cactus/a2c6975a160be97c000c93b480183deb to your computer and use it in GitHub Desktop.
<?php
class DownloadDiscoveryArticleCommand
{
public $batchSize = 10;
public function handle()
{
$totalItems = $this->getTotalJournalsFromDiscovery();
// Create jobs for each batch of items
for ($i = 0; $i < $totalItems; $i += $this->batchSize) {
$jobs[] = (new FetchDataFromDiscovery($i, $this->batchSize))->delay(/* Add delay mechanism as per requirement */);
}
$batch = Bus::batch($jobs)
->then(function (Batch $batch) {
// All jobs completed successfully
CacheUserJournalNewletter::dispatch();
})->catch(function (Batch $batch, \Throwable $e) {
// Batch failed retry
$this->error('Batch failed: ' . $e->getMessage());
})->finally(function (Batch $batch) {
// For logging purpose
$this->info('Batch processing completed');
})->dispatch();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment