diff --git a/.docker/php/Dockerfile b/.docker/php/Dockerfile index 8b8a3247..80fead06 100644 --- a/.docker/php/Dockerfile +++ b/.docker/php/Dockerfile @@ -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 diff --git a/.docker/php/DockerfileDebian b/.docker/php/DockerfileDebian index a1ce506c..9463789d 100644 --- a/.docker/php/DockerfileDebian +++ b/.docker/php/DockerfileDebian @@ -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 diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 8d762c24..c88fa6b5 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -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(); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 7397dc2c..883b5fa0 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -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"); + } + } + ); + } } diff --git a/include/constants.php b/include/constants.php index e4b22807..bfd90da8 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@