PHP code example of integration-helper / process-runner
1. Go to this page and download the library: Download integration-helper/process-runner 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/ */
integration-helper / process-runner example snippets
use IntegrationHelper\ProcessRunner\Model\ProcessProfileManager
use Example\SomeExtension\Model\RunImportProfile
class ClassName {
public function __construct(
...
protected ProcessProfileManager $processProfileManager
){}
private function runMultiProcessing()
{
$result = [...,...,...];
$total = count($result);
$batchSize = ceil($total / 50);
$previousBatchSize = 1;
$i = 1;
while ($i <= 50) {
$batch = sprintf('%s-%s', $previousBatchSize, $i*$batchSize);
$previousBatchSize = $i*$batchSize;
$code = sprintf('%s-%s', ConstraintsInterface::CURRENT_PROFILE_CODE, $batch);
$data = [
\IntegrationHelper\ProcessRunner\Api\ConstraintsInterface::IDENTITY => 'unique_profile_name_here',
\IntegrationHelper\ProcessRunner\Api\ConstraintsInterface::CODE => $code,
\IntegrationHelper\ProcessRunner\Api\ConstraintsInterface::MODEL => RunImportProfile::class,
\IntegrationHelper\ProcessRunner\Api\ConstraintsInterface::MODEL_METHOD_ARGUMENTS => json_encode(
[
'profile' => 'unique_profile_name_here',
'batch' => $batch
]
)
];
$i++;
$this->processProfileManager->create($data);
}
}
}
namespace Example\SomeExtension\Model;
class RunImportProfile implements \IntegrationHelper\ProcessRunner\Model\ModelInstanceInterface
{
public function runProcess(array $params = []): bool
{
$profile = $params['profile'] ?? false;
$batch = $params['batch'] ?? false;
if(!$profile) return;
$result = false;
try {
// Code here
} catch (\Exception $e) {
$result = true;
}
return !$result;
}
}