İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\NaksSyncService;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class NaksSyncController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle upcoming sync trigger from another project.
|
||||
* This endpoint is called by other projects when they update a record.
|
||||
*/
|
||||
public function triggerSync(Request $request, NaksSyncService $syncService)
|
||||
{
|
||||
$validated = $request->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'
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user