webmozarts / console-parallelization

Enables the parallelization of Symfony Console commands.
MIT License
222 stars 19 forks source link

Documentation for ::getParallelExecutableFactory #205

Closed LouisGarret closed 1 year ago

LouisGarret commented 1 year ago

Hello,

Is it possible to provide documentation for using the ::getParallelExecutableFactory ?

It's not clear, and I don't understand how to use it, I have many command using the runBeforeFirstCommand function before the upgrade.

Regards, Louis

LouisGarret commented 1 year ago

Ok I've found a solution, adding this in all my command

    public function configureParallelExecutableFactory(
        ParallelExecutorFactory $parallelExecutorFactory,
        InputInterface $input,
        OutputInterface $output
    ): ParallelExecutorFactory {
        return parent::configureParallelExecutableFactory(
            $parallelExecutorFactory,
            $input,
            $output
        )->withRunBeforeFirstCommand(fn () => $this->runBeforeFirstCommand($input, $output));
    }

Why did you move that to hooks ? It's not used frequently ?

theofidry commented 1 year ago

Sorry for the late reply.

Why did you move that to hooks ? It's not used frequently ?

It's not rare, but not super common neither.

Regarding your sample there is a mistake, it should be:

public function configureParallelExecutableFactory(
        ParallelExecutorFactory $parallelExecutorFactory,
        InputInterface $input,
        OutputInterface $output
    ): ParallelExecutorFactory {
        // You can skip calling the parent here. If you check the parent implementation it is just a placeholder
        // very much like the Symfony `Command::interact()` or others.

        return $parallelExecutorFactory
            // The callable gets its own input/output, as it might differ from the current ones
             ->withRunBeforeFirxstCommand(fn ($input, $output) => $this->runBeforeFirstCommand($input, $output));
            // Alternatively if you are on PHP 8.1 and do not inject any extra data to your runBeforeFirstCommand() implementation:
             ->withRunBeforeFirxstCommand($this->runBeforeFirstCommand(...));
    }
theofidry commented 1 year ago

Edit: there actually is configureParallelExecutableFactory() which works better