Replies: 7 comments 8 replies
-
WorkaroundIf your laravel deployment with docker is doing things the
|
Beta Was this translation helpful? Give feedback.
-
Totally agree with the proposal. Current implementation breaks 12-factor methodology. |
Beta Was this translation helpful? Give feedback.
-
Previously that issue was mentioned in #38429 Also, one of the solutions is to extend comand description like $schedule->command(TestLogCommand::class)->everyMinute()->thenWithOutput(function (Stringable $output) {
echo $output;
}); |
Beta Was this translation helpful? Give feedback.
-
This is a challenge to understand when deploying to k8s - my
becomes
so Datadog and K8s have no way to get the command's logs. |
Beta Was this translation helpful? Give feedback.
-
Run in background scheduled task is not compatible with stdout logging in laravel. See #50085 (comment) |
Beta Was this translation helpful? Give feedback.
-
Instead of building a bicycle with macroses I've ended up using the patch for laravel/framework scheduler_dont_truncate_output.patch
--- a/src/Illuminate/Console/Scheduling/CommandBuilder.php
+++ b/src/Illuminate/Console/Scheduling/CommandBuilder.php
@@ -33,7 +33,7 @@
$output = ProcessUtils::escapeArgument($event->output);
return $this->ensureCorrectUser(
- $event, $event->command.($event->shouldAppendOutput ? ' >> ' : ' > ').$output.' 2>&1'
+ $event, $event->command.' 2>&1'
);
}
@@ -56,7 +56,7 @@
}
return $this->ensureCorrectUser($event,
- '('.$event->command.$redirect.$output.' 2>&1 ; '.$finished.' "$?") > '
+ '('.$event->command.' 2>&1 ; '.$finished.' "$?") > '
.ProcessUtils::escapeArgument($event->getDefaultOutput()).' 2>&1 &'
);
}
--- a/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php
+++ b/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php
@@ -132,6 +132,8 @@
}
$this->eventsRan = true;
+
+ $this->handleEventOutput($event);
}
if ($events->contains->isRepeatable()) {
@@ -145,6 +147,18 @@
}
}
+ protected function handleEventOutput(Event $event): void
+ {
+ if (!empty($event->outputBufferStdout)) {
+ $this->components->info($event->outputBufferStdout);
+ $this->newLine();
+ }
+
+ if (!empty($event->outputBufferStderr)) {
+ $this->components->error($event->outputBufferStderr);
+ }
+ }
+
/**
* Run the given single server event.
*
@@ -252,6 +266,8 @@
}
$this->eventsRan = true;
+
+ $this->handleEventOutput($event);
}
Sleep::usleep(100000);
--- a/src/Illuminate/Console/Scheduling/Event.php
+++ b/src/Illuminate/Console/Scheduling/Event.php
@@ -128,6 +128,16 @@
*/
public $shouldAppendOutput = false;
+ /**
+ * @var string The output buffer for stdout.
+ */
+ public $outputBufferStdout = '';
+
+ /**
+ * @var string The output buffer for stderr.
+ */
+ public $outputBufferStderr = '';
+
/**
* The array of callbacks to be run before the event is started.
*
@@ -289,7 +299,13 @@
{
return Process::fromShellCommandline(
$this->buildCommand(), base_path(), null, null, null
- )->run();
+ )->run(function($type, $buffer) {
+ if ($type === Process::ERR) {
+ $this->outputBufferStderr .= $buffer;
+ } else {
+ $this->outputBufferStdout .= $buffer;
+ }
+ });
}
/** To add patch automatically while composer install I've used the composer package cweagans/composer-patches Here is my patch definition in composer.json
...
"extra": {
"laravel": {
"dont-discover": []
},
"patches": {
"laravel/framework": {
"scheduler_dont_truncate_output": "./patches/scheduler_dont_truncate_output.patch"
}
},
"enable-patching": true
},
...
Maybe only stdout matter since it used 2>&1 directive. But I hope this might help someone. The scheduler run command is really stupidly written. Logging to a file breaks 12factor app conseption. I hope in a newer version of the framework something good will be done with it. |
Beta Was this translation helpful? Give feedback.
-
Looks like whoever was working on Laravel Cloud realized that people might want to actually see the output from commands. So they made this change. framework/src/Illuminate/Console/Scheduling/Event.php Lines 198 to 207 in 94c2696 Now I get that sometimes it takes encountering the situation yourself to realize that the way it is set up, doesn't work. But tying this to only for Laravel Cloud seems like a very narrow solution and really should be broadened to support those that are running Laravel in other environments. |
Beta Was this translation helpful? Give feedback.
-
Laravel Version
9.29.0
PHP Version
8.1.20
Database Driver & Version
No response
Description
Scheduled Tasks seem to force output to /dev/null unless a local disk file is provided to write output to.
On Docker-based or similar deploy-code / spin-up-instances hosting services like heroku.com or fly.io etc. local files are usually ephemeral and thus local log files are quite useless.
These hosts usually offer a live scrolling app output console log that can be monitored, very useful to catch live exceptions or view logged notices/warnings etc.
It would seem very desirable and necessary to have the option to let
schedule:run
allow laravel Schedule Events' output to proceed on to STDOUT along with all other app output. Suppressing it to /dev/null with no option to allow it through to STDOUT seems like blocking useful options for many deployment environments.Steps To Reproduce
->line()
or->table()
or whatnotSome relevant links
Beta Was this translation helpful? Give feedback.
All reactions