mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
schedule task log to docker process when running in docker environment
This commit is contained in:
@@ -6,6 +6,8 @@ use App\Http\Middleware\Locale;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Support\Assets\Css;
|
||||
use Filament\Support\Facades\FilamentAsset;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Console\Events\ScheduledTaskStarting;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
@@ -44,6 +46,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
if (env('APP_ENV') == "production" && in_array($forceScheme, ['https', 'http'])) {
|
||||
URL::forceScheme($forceScheme);
|
||||
}
|
||||
$this->customScheduleTask();
|
||||
|
||||
Filament::serving(function () {
|
||||
Filament::registerNavigationGroups([
|
||||
@@ -64,4 +67,26 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
do_action('nexus_boot');
|
||||
}
|
||||
|
||||
private function customScheduleTask(): void
|
||||
{
|
||||
if (!isRunningInConsole()) {
|
||||
return;
|
||||
}
|
||||
/** @var Dispatcher $eventDispatcher */
|
||||
$eventDispatcher = $this->app->make(Dispatcher::class);
|
||||
|
||||
$eventDispatcher->listen(
|
||||
events: [ScheduledTaskStarting::class],
|
||||
listener: static function (ScheduledTaskStarting $event): void {
|
||||
$event->task->onOneServer()->withoutOverlapping();
|
||||
// When we are using stterr as output for logs then schedule tasks will not output
|
||||
// any logs due the /dev/null usage. Let's fix this by appending the output to
|
||||
// the docker process.
|
||||
if (getenv("RUNNING_IN_DOCKER") == "1" && $event->task->output === $event->task->getDefaultOutput()) {
|
||||
$event->task->appendOutputTo("/proc/1/fd/1");
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user