schedule task log to docker process when running in docker environment

This commit is contained in:
xiaomlove
2025-05-19 13:18:47 +07:00
parent 273fa3e1b8
commit 3dfe0cbd27
5 changed files with 44 additions and 17 deletions
+1
View File
@@ -76,6 +76,7 @@ RUN echo "error_log = /dev/stderr" >> /usr/local/etc/php/conf.d/error-logging.in
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
ENV LOG_CHANNEL=stderr
ENV RUNNING_IN_DOCKER=1
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
+1
View File
@@ -83,6 +83,7 @@ RUN echo "error_log = /dev/stderr" >> /usr/local/etc/php/conf.d/error-logging.in
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
ENV LOG_CHANNEL=stderr
ENV RUNNING_IN_DOCKER=1
# 复制入口脚本
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
+15 -15
View File
@@ -35,23 +35,23 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule)
{
$schedule->command('cache:prune-stale-tags')->hourly();
$schedule->command('exam:assign_cronjob')->everyMinute()->withoutOverlapping();
$schedule->command('exam:checkout_cronjob')->everyFiveMinutes()->withoutOverlapping();
$schedule->command('exam:update_progress --bulk=1')->hourly()->withoutOverlapping();
$schedule->command('backup:cronjob')->everyMinute()->withoutOverlapping();
$schedule->command('hr:update_status')->everyTenMinutes()->withoutOverlapping();
$schedule->command('hr:update_status --ignore_time=1')->hourly()->withoutOverlapping();
$schedule->command('user:delete_expired_token')->dailyAt('04:00')->withoutOverlapping();
$schedule->command('exam:assign_cronjob')->everyMinute();
$schedule->command('exam:checkout_cronjob')->everyFiveMinutes();
$schedule->command('exam:update_progress --bulk=1')->hourly();
$schedule->command('backup:cronjob')->everyMinute();
$schedule->command('hr:update_status')->everyTenMinutes();
$schedule->command('hr:update_status --ignore_time=1')->hourly();
$schedule->command('user:delete_expired_token')->dailyAt('04:00');
$schedule->command('claim:settle')->hourly()->when(function () {
return Carbon::now()->format('d') == '01';
})->withoutOverlapping();
$schedule->command('meilisearch:import')->weeklyOn(1, "03:00")->withoutOverlapping();
$schedule->command('torrent:load_pieces_hash')->dailyAt("01:00")->withoutOverlapping();
$schedule->job(new CheckQueueFailedJobs())->everySixHours()->withoutOverlapping();
$schedule->job(new ThirdPartyJob())->everyMinute()->withoutOverlapping();
$schedule->job(new MaintainPluginState())->everyMinute()->withoutOverlapping();
$schedule->job(new UpdateIsSeedBoxFromUserRecordsCache())->everySixHours()->withoutOverlapping();
$schedule->job(new CheckCleanup())->everyFifteenMinutes()->withoutOverlapping();
});
$schedule->command('meilisearch:import')->weeklyOn(1, "03:00");
$schedule->command('torrent:load_pieces_hash')->dailyAt("01:00");
$schedule->job(new CheckQueueFailedJobs())->everySixHours();
$schedule->job(new ThirdPartyJob())->everyMinute();
$schedule->job(new MaintainPluginState())->everyMinute();
$schedule->job(new UpdateIsSeedBoxFromUserRecordsCache())->everySixHours();
$schedule->job(new CheckCleanup())->everyFifteenMinutes();
}
+25
View File
@@ -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");
}
}
);
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.0');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-05-18');
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.1');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-05-19');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");