Skip to content

Commit acb45b5

Browse files
committed
Pass Laravel context through with schedule tasks
1 parent 49c39b6 commit acb45b5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Illuminate/Console/Scheduling/Event.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Contracts\Container\Container;
1212
use Illuminate\Contracts\Debug\ExceptionHandler;
1313
use Illuminate\Contracts\Mail\Mailer;
14+
use Illuminate\Log\Context\Repository;
1415
use Illuminate\Support\Arr;
1516
use Illuminate\Support\Facades\Date;
1617
use Illuminate\Support\Stringable;
@@ -197,8 +198,10 @@ protected function start($container)
197198
*/
198199
protected function execute($container)
199200
{
201+
$context = escapeshellarg(json_encode($container[Repository::class]->dehydrate()));
202+
200203
return Process::fromShellCommandline(
201-
$this->buildCommand(), base_path(), null, null, null
204+
$this->buildCommand(), base_path(), ['__LARAVEL_CONTEXT' => $context], null, null
202205
)->run(
203206
laravel_cloud()
204207
? fn ($type, $line) => fwrite($type === 'out' ? STDOUT : STDERR, $line)

src/Illuminate/Log/Context/ContextServiceProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Contracts\Log\ContextLogProcessor as ContextLogProcessorContract;
66
use Illuminate\Queue\Events\JobProcessing;
77
use Illuminate\Queue\Queue;
8+
use Illuminate\Support\Env;
89
use Illuminate\Support\Facades\Context;
910
use Illuminate\Support\ServiceProvider;
1011

@@ -29,6 +30,10 @@ public function register()
2930
*/
3031
public function boot()
3132
{
33+
$env = Env::get('__LARAVEL_CONTEXT', '');
34+
/** @phpstan-ignore staticMethod.notFound */
35+
Context::hydrate(json_decode($env, true));
36+
3237
Queue::createPayloadUsing(function ($connection, $queue, $payload) {
3338
/** @phpstan-ignore staticMethod.notFound */
3439
$context = Context::dehydrate();

0 commit comments

Comments
 (0)