Last active
February 5, 2025 07:20
-
-
Save shreyanshp-cactus/a2c6975a160be97c000c93b480183deb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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