2025-01-21 14:57:54 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2025-05-22 17:58:22 +08:00
|
|
|
use App\Services\Plugin\HookManager;
|
|
|
|
|
use App\Services\UpdateService;
|
2025-01-21 14:57:54 +08:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
use Laravel\Octane\Facades\Octane;
|
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
use Illuminate\Support\Facades\Artisan;
|
2025-05-22 17:58:22 +08:00
|
|
|
use Laravel\Octane\Events\WorkerStarting;
|
2025-01-21 14:57:54 +08:00
|
|
|
|
2025-05-22 17:58:22 +08:00
|
|
|
class OctaneServiceProvider extends ServiceProvider
|
2025-01-21 14:57:54 +08:00
|
|
|
{
|
|
|
|
|
public function register(): void
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function boot(): void
|
|
|
|
|
{
|
|
|
|
|
if ($this->app->runningInConsole()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-05-22 17:58:22 +08:00
|
|
|
if ($this->app->bound('octane')) {
|
|
|
|
|
$this->app['events']->listen(WorkerStarting::class, function () {
|
|
|
|
|
app(UpdateService::class)->updateVersionCache();
|
|
|
|
|
HookManager::reset();
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-01-21 14:57:54 +08:00
|
|
|
// 每半钟执行一次调度检查
|
|
|
|
|
Octane::tick('scheduler', function () {
|
|
|
|
|
$lock = Cache::lock('scheduler-lock', 30);
|
|
|
|
|
|
|
|
|
|
if ($lock->get()) {
|
|
|
|
|
try {
|
|
|
|
|
Artisan::call('schedule:run');
|
|
|
|
|
} finally {
|
|
|
|
|
$lock->release();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})->seconds(30);
|
|
|
|
|
}
|
|
|
|
|
}
|