validate([ 'module' => 'required|string', 'source_project' => 'required|string' ]); $module = $validated['module']; $source = $validated['source_project']; Log::info("Received NAKS Sync Trigger from [$source] for module [$module]"); // Prevent infinite loops if logic isn't careful, but NaksSyncService checks timestamps. // We will queue the actual sync to perform it in background // We use 'dispatch' helper or creating a Job closure // We can run the sync service directly here if we want immediate feedback, but it might take time. // Best practice is to queue it. // Let's create a closure job or reuse existing mechanism. // Since we don't have a dedicated "RunSyncJob", we'll do it inline with fast execution or // dispatch a closure. dispatch(function () use ($syncService, $module) { try { // Sync specific module from all projects (or finding the specific source, but the service supports 'all' or filtered) // The service reads from 'api/project-app-urls' list. // We should sync 'all' projects to be safe, or we could optimize later. $syncService->sync($module); } catch (\Exception $e) { Log::error("Error in Queued NAKS Sync: " . $e->getMessage()); } }); return response()->json([ 'message' => 'Sync triggered successfully', 'status' => 'queued' ]); } }