You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Artisan::call() it's not possible to capture the output of any sub-commands in the same output buffer. This has become a problem because we have a long-running index task and we'd like to know the progress as you would see by calling php artisan scout:index manually.
See the brief example below:
namespaceApp\Console\Commands;
useIlluminate\Console\Command;
useArtisan;
class CreateScoutIndex extends Command
{
/** * The name and signature of the console command. * * @var string */protected$signature = 'scoutindex:create';
/** * The console command description. * * @var string */protected$description = 'Creates the scout ElasticSearch Index';
/** * Create a new command instance. * * @return void */publicfunction__construct()
{
parent::__construct();
}
/** * Execute the console command. * * @return mixed */publicfunctionhandle()
{
/** * 1. Create the ElasticSearch index here with our own custom Analysers, field types etc. *//** * 2. Call the scout import command, we want to know the progress right? * Except that isn't possible because the command has to completely finish before returning * the output. */
Artisan::call('scout:import', [ 'model' => 'App\\SomeModel' ]);
$this->line(Artisan::output());
/** * 3. Any other logic here; alias rotation, cleanup etc. */
}
}
A couple of things I've tried:
// call doesn't accept a third parameter even though this turns up in Google a lot - perhaps this used to work with an older version of Laravel.
Artisan::call('scout:import', [ 'model' => 'App\\SomeModel' ], $this->getOutput());
// This almost works, but it's dangerous to re-use the same instance and causes further issues if you call multiple at the same time:$this->call('scout:import', [ 'model' => 'App\\SomeModel' ]);
$this->call('scout:import', [ 'model' => 'App\\SomeOtherModel' ]); // This seems to mess up scout's progress counts
Are there any known work-arounds for this? Everything else I've seen suggests creating a new OutputBuffer instance, but this would have the same effect as my example class, where the output only shows after command completion.
Steps To Reproduce:
See above class.
The text was updated successfully, but these errors were encountered:
I think we would just need to add a third parameter to pass an output buffer to the Foundation\Console\Kernel@call method, which would then pass it to the Console\Application@call method. /cc @themsaid
Description:
When using
Artisan::call()
it's not possible to capture the output of any sub-commands in the same output buffer. This has become a problem because we have a long-running index task and we'd like to know the progress as you would see by callingphp artisan scout:index
manually.See the brief example below:
A couple of things I've tried:
Are there any known work-arounds for this? Everything else I've seen suggests creating a new OutputBuffer instance, but this would have the same effect as my example class, where the output only shows after command completion.
Steps To Reproduce:
See above class.
The text was updated successfully, but these errors were encountered: