Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
26 / 26 |
| DataDistributor | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
26 / 26 |
| __construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
| handle | |
100.00% |
1 / 1 |
3 | |
100.00% |
22 / 22 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\Collect\Console\Commands; |
| 4 | |
| 5 | use Exception; |
| 6 | use Qmp\Laravel\AsyncProcessFactory\Traits\{ProcessFactory, ProcessFactoryStatus}; |
| 7 | use Qmp\Laravel\CommandsLaravel\Middleware\Core\Middleware; |
| 8 | use Qmp\Laravel\CommandsLaravel\Middleware\Library\Monitoring\{CreateParentProcess, UpdateParentProcessAsync}; |
| 9 | use Qmp\Laravel\ToolsLaravel\Traits\Timer; |
| 10 | |
| 11 | class DataDistributor extends \Commando |
| 12 | { |
| 13 | use Timer, ProcessFactory, ProcessFactoryStatus; |
| 14 | /** |
| 15 | * The name and signature of the console command. |
| 16 | * |
| 17 | * @var string |
| 18 | */ |
| 19 | protected $signature = 'collect:data-distributor'; |
| 20 | |
| 21 | /** |
| 22 | * The console command description. |
| 23 | * |
| 24 | * @var string |
| 25 | */ |
| 26 | protected $description = 'Split tracker collection and process it'; |
| 27 | |
| 28 | /** |
| 29 | * Undocumented variable |
| 30 | * |
| 31 | * @var array |
| 32 | */ |
| 33 | protected $toVerify = ['ttl', 'running']; |
| 34 | |
| 35 | /** |
| 36 | * Undocumented variable |
| 37 | * |
| 38 | * @var integer |
| 39 | */ |
| 40 | protected $maxTry = 1; |
| 41 | |
| 42 | /** |
| 43 | * The max process |
| 44 | * |
| 45 | * @var integer |
| 46 | */ |
| 47 | protected $maxProcess = 20; |
| 48 | |
| 49 | /** |
| 50 | * Undocumented function |
| 51 | */ |
| 52 | public function __construct() |
| 53 | { |
| 54 | parent::__construct(); |
| 55 | |
| 56 | $middlewares = [ |
| 57 | CreateParentProcess::class, |
| 58 | UpdateParentProcessAsync::class |
| 59 | ]; |
| 60 | |
| 61 | $this->middleware($middlewares); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Execute the console command. |
| 66 | * |
| 67 | * @return void |
| 68 | * @throws Exception |
| 69 | */ |
| 70 | public function handle(): void |
| 71 | { |
| 72 | $this->startTimer('total'); |
| 73 | |
| 74 | $data = $this->middlewareData(UpdateParentProcessAsync::class) |
| 75 | ->transfert(CreateParentProcess::class, ['id']); |
| 76 | $data->log['maxProcess'] = $this->maxProcess; |
| 77 | |
| 78 | try { |
| 79 | $processes = $this->processVerify(); |
| 80 | |
| 81 | if ($processes->count() > 0) { |
| 82 | $this->createProcessFactory('collect:data-distributor-process') |
| 83 | ->addEnvs(Middleware::IS_SYSTEM); |
| 84 | $this->info('Creating factory'); |
| 85 | |
| 86 | $processes->each(function ($process) use ($data) { |
| 87 | $this->line('<info>Add process to factory : </info>' . $process->id); |
| 88 | $this->addProcess([$process->id, $data->id]); |
| 89 | }); |
| 90 | |
| 91 | $this->output->write('<info>Starting factory ...</info>'); |
| 92 | $this->startDetachedProcesses(); |
| 93 | $this->output->write(' done'); |
| 94 | } else { |
| 95 | $this->middlewareData(UpdateParentProcessAsync::class)->set(['forcedPass' => true]); |
| 96 | } |
| 97 | |
| 98 | $this->line(''); |
| 99 | |
| 100 | $data->log['duration'] = $this->getTimer('total'); |
| 101 | } catch (Exception $e) { |
| 102 | $data->error = $this->reportException($e); |
| 103 | } |
| 104 | } |
| 105 | } |