1. Go to this page and download the library: Download wwwision/batch-processing library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wwwision / batch-processing example snippets
use Neos\Flow\Annotations as Flow;
use Wwwision\BatchProcessing\BatchProcessRunner;
class SomeCommandController extends CommandController
{
public function someMainCommand(): void
{
$runner = new BatchProcessRunner('somebatch');
$runner->start();
}
/**
* @param int $offset zero based offset
* @param int $limit size of the batch to process
* @internal
*/
public function someBatchCommand(int $offset, int $limit): void
{
// process batch of size $limit from $offset
}
}
$progressHandler = ProgressBarRenderer::create($this->output->getOutput());
$runner = new BatchProcessRunner('some:batch:command', null, $progressHandler);
$progressPipe = new ProgressPipe();
for ($i = $offset; $i < ($offset + $limit); $i ++) {
try {
// do something
} catch (SomeException $e) {
$progressPipe->error($e->getMessage());
}
$progressPipe->set($i);
}
$runner->start($totalAmountOfTasks);
$this->outputLine('This might be outputted before the runner has been finished!')
$runner->onFinish(function() {
$this->outputLine('This will be outputted when all tasks have been processed');
});
$runner->start($totalAmountOfTasks);