Problem/Motivation

This is part of drush:deploy so lets get it into core before that command ports in.

Steps to reproduce

None

Proposed resolution

Add the command

Remaining tasks

None

User interface changes

None

Introduced terminology

None

API changes

None

AI-Assisted: Yes

Data model changes

None

Release notes snippet

None

Issue fork drupal-3627548

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

moshe weitzman created an issue. See original summary.

moshe weitzman’s picture

Issue summary: View changes

catch’s picture

Does the core cli have a way to fork processes? If it does, then we could try to execute each prewarmable thing in parallel so that they all happen at the same time (and hence finish as soon as possible, ideally before any requests actually come in). Even if this is possible, could happen in a follow-up.

moshe weitzman’s picture

Google suggests something like below which seems simple enough. I would personally leave it for Contrib or a followup, but I'll change it if anyone really wants.

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;

class ParallelTasksCommand extends Command
{
    protected static $defaultName = 'app:run-parallel';

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        // Define your background processes
        $processes = [
            new Process(['php', 'bin/console', 'app:task-one']),
            new Process(['php', 'bin/console', 'app:task-two']),
        ];

        // Launch all processes asynchronously
        foreach ($processes as $process) {
            $process->start();
        }

        // Wait for all of them to finish (blocking block)
        foreach ($processes as $process) {
            while ($process->isRunning()) {
                // Optional: Read real-time output or sleep to save CPU cycles
                usleep(100000); 
            }
        }

        $output->writeln('All parallel tasks completed.');
        return Command::SUCCESS;
    }
}

moshe weitzman’s picture

Oh, that approach only works if each process runs a CLI command like dr php:eval "FieldDfinintion:warm()" and so on. We don't have a php:eval command yet.

moshe weitzman’s picture

Assigned: moshe weitzman » Unassigned
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Okay ran this locally

First I did a drush cr and checked the cache_discovery table which was at 42 after clear
Ran ddev exec dr cache:warm
Checked the table again and it was 90

So definitely appears to be working. Referencing other test coverage for cli commands this seems in par with those.

LGTM.