settings = $settings; $this->schedulerService = $schedulerService; } /** * Запуск планировщика по HTTP (для cron-job.org и аналогов). * Требует api_key в query, совпадающий с настройкой cron.api_key. */ public function runSchedule(Request $request): JsonResponse { $mode = $this->settings->get('cron.mode', 'disabled'); if ($mode !== 'cron_job_org') { return new JsonResponse(['error' => 'Scheduler is not in cron-job.org mode'], Response::HTTP_FORBIDDEN); } $apiKey = $request->get('api_key', ''); $expectedKey = $this->settings->get('cron.api_key', ''); if ($expectedKey === '' || $apiKey === '' || !hash_equals($expectedKey, $apiKey)) { return new JsonResponse(['error' => 'Invalid or missing API key'], Response::HTTP_UNAUTHORIZED); } // Увеличиваем лимит времени выполнения при запуске по HTTP, чтобы снизить риск timeout $limit = 300; // 5 минут if (function_exists('set_time_limit')) { @set_time_limit($limit); } if (function_exists('ini_set')) { @ini_set('max_execution_time', (string) $limit); } $result = $this->schedulerService->run(true); $data = [ 'success' => true, 'executed' => count($result->executed), 'failed' => count($result->failed), 'skipped' => count($result->skipped), ]; return new JsonResponse($data); } }