From 1b7ec4def006e1f59e8167a1ffdcb3c69f7d5c03 Mon Sep 17 00:00:00 2001 From: JORGE Date: Tue, 7 Jan 2025 15:44:35 -0400 Subject: [PATCH] [TM-1531] move creation of delayed job to improve speed notification visibility --- .../TerrafundClipGeometryController.php | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php index f37ecce3..fa2a1606 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php @@ -5,12 +5,14 @@ use App\Helpers\GeometryHelper; use App\Http\Resources\DelayedJobResource; use App\Jobs\FixPolygonOverlapJob; +use App\Models\DelayedJob; use App\Models\DelayedJobProgress; use App\Models\V2\Sites\CriteriaSite; use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SitePolygon; use App\Services\PolygonService; use Illuminate\Http\Request; +use Illuminate\Http\Response; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; @@ -62,6 +64,17 @@ public function clipOverlappingPolygonsOfProjectBySite(string $uuid) return response()->json(['message' => 'No polygons found for the project.'], 204); } + $delayedJob = DelayedJobProgress::create([ + 'processed_content' => 0, + 'metadata' => [ + 'entity_id' => $site->id, + 'entity_type' => get_class($site), + 'entity_name' => $site->name, + ], + 'created_by' => $user->id, + 'is_acknowledged' => false, + 'name' => 'Polygon Fix', + ]); $allPolygonUuids = []; foreach ($polygonUuids as $uuid) { $polygonOverlappingExtraInfo = CriteriaSite::forCriteria(PolygonService::OVERLAPPING_CRITERIA_ID) @@ -84,20 +97,16 @@ public function clipOverlappingPolygonsOfProjectBySite(string $uuid) $uniquePolygonUuids = array_unique($allPolygonUuids); if (empty($uniquePolygonUuids)) { + DelayedJob::where('uuid', $delayedJob->uuid)->update([ + 'status' => DelayedJob::STATUS_FAILED, + 'payload' => json_encode(['error' => 'No overlapping polygons found for the project.']), + 'status_code' => Response::HTTP_INTERNAL_SERVER_ERROR, + ]); + return response()->json(['message' => 'No overlapping polygons found for the project.'], 204); } - $delayedJob = DelayedJobProgress::create([ - 'processed_content' => 0, - 'metadata' => [ - 'entity_id' => $site->id, - 'entity_type' => get_class($site), - 'entity_name' => $site->name, - ], - 'created_by' => $user->id, - 'is_acknowledged' => false, - 'name' => 'Polygon Fix', - ]); + $job = new FixPolygonOverlapJob($delayedJob->id, $uniquePolygonUuids, $user->id); dispatch($job);