From 213cf6af7ab84cd5c1b434544f360e92f395c453 Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Fri, 29 Nov 2024 13:22:52 -0400 Subject: [PATCH 1/8] [TM-1536] add delayed job progress --- .../TerrafundClipGeometryController.php | 21 ++++++++-- .../TerrafundCreateGeometryController.php | 16 ++++++-- .../Resources/DelayedJobProgressResource.php | 25 ++++++++++++ app/Jobs/FixPolygonOverlapJob.php | 8 ++-- app/Jobs/RunSitePolygonsValidationJob.php | 10 ++++- app/Models/DelayedJobProgress.php | 38 +++++++++++++++++++ app/Services/PolygonService.php | 9 ++++- ...103000_add_fields_to_delayed_job_table.php | 33 ++++++++++++++++ 8 files changed, 148 insertions(+), 12 deletions(-) create mode 100644 app/Http/Resources/DelayedJobProgressResource.php create mode 100644 app/Models/DelayedJobProgress.php create mode 100644 database/migrations/2024_11_27_103000_add_fields_to_delayed_job_table.php diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php index 2e7d5ead2..7d23cb08b 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php @@ -4,8 +4,10 @@ use App\Helpers\GeometryHelper; use App\Http\Resources\DelayedJobResource; +use App\Http\Resources\DelayedJobProgressResource; 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; @@ -21,11 +23,16 @@ class TerrafundClipGeometryController extends TerrafundCreateGeometryController public function clipOverlappingPolygonsBySite(string $uuid) { + Log::info('Clipping polygons by site', ['uuid' => $uuid]); ini_set('max_execution_time', self::MAX_EXECUTION_TIME); ini_set('memory_limit', '-1'); $user = Auth::user(); $polygonUuids = GeometryHelper::getSitePolygonsUuids($uuid)->toArray(); - $delayedJob = DelayedJob::create(); + $delayedJob = DelayedJobProgress::create([ + 'total_content' => count($polygonUuids), + 'processed_content' => 0, + 'progress' => 0, + ]); $job = new FixPolygonOverlapJob($delayedJob->id, $polygonUuids, $user->id); dispatch($job); @@ -41,7 +48,11 @@ public function clipOverlappingPolygonsOfProjectBySite(string $uuid) $sitePolygon = Site::isUuid($uuid)->first(); $projectId = $sitePolygon->project_id ?? null; $polygonUuids = GeometryHelper::getProjectPolygonsUuids($projectId); - $delayedJob = DelayedJob::create(); + $delayedJob = DelayedJobProgress::create([ + 'total_content' => count($polygonUuids), + 'processed_content' => 0, + 'progress' => 0, + ]); $job = new FixPolygonOverlapJob($delayedJob->id, $polygonUuids, $user->id); dispatch($job); @@ -89,7 +100,11 @@ public function clipOverlappingPolygons(Request $request) $delayedJob = null; if (! empty($uniquePolygonUuids)) { $user = Auth::user(); - $delayedJob = DelayedJob::create(); + $delayedJob = DelayedJobProgress::create([ + 'total_content' => count($uniquePolygonUuids), + 'processed_content' => 0, + 'progress' => 0, + ]); $job = new FixPolygonOverlapJob($delayedJob->id, $polygonUuids, $user->id); dispatch($job); } diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php index 262687b1c..5f5aa7ada 100755 --- a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php @@ -8,6 +8,7 @@ use App\Jobs\InsertGeojsonToDBJob; use App\Jobs\RunSitePolygonsValidationJob; use App\Models\DelayedJob; +use App\Models\DelayedJobProgress; use App\Models\V2\PolygonGeometry; use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SitePolygon; @@ -892,6 +893,7 @@ function ($attribute, $value, $fail) { public function validateOverlapping(Request $request) { + Log::info('overlapping validation request'); $uuid = $request->input('uuid'); return $this->handlePolygonValidation( @@ -1205,7 +1207,7 @@ public function runValidationPolygon(string $uuid) public function sendRunValidationPolygon(Request $request) { - + Log::info("here criteria data"); $uuid = $request->input('uuid'); $this->runValidationPolygon($uuid); $criteriaData = $this->getCriteriaData($request); @@ -1219,7 +1221,11 @@ public function runSiteValidationPolygon(Request $request) $uuid = $request->input('uuid'); $sitePolygonsUuids = GeometryHelper::getSitePolygonsUuids($uuid)->toArray(); - $delayedJob = DelayedJob::create(); + $delayedJob = DelayedJobProgress::create([ + 'total_content' => count($sitePolygonsUuids), + 'processed_content' => 0, + 'progress' => 0, + ]); $job = new RunSitePolygonsValidationJob($delayedJob->id, $sitePolygonsUuids); dispatch($job); @@ -1235,7 +1241,11 @@ public function runPolygonsValidation(Request $request) { try { $uuids = $request->input('uuids'); - $delayedJob = DelayedJob::create(); + $delayedJob = DelayedJobProgress::create([ + 'total_content' => count($uuids), + 'processed_content' => 0, + 'progress' => 0, + ]); $job = new RunSitePolygonsValidationJob($delayedJob->id, $uuids); dispatch($job); diff --git a/app/Http/Resources/DelayedJobProgressResource.php b/app/Http/Resources/DelayedJobProgressResource.php new file mode 100644 index 000000000..21984bca1 --- /dev/null +++ b/app/Http/Resources/DelayedJobProgressResource.php @@ -0,0 +1,25 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'message' => $this->message ?? 'Job dispatched', + 'job_uuid' => $this->uuid, + 'progress' => $this->progress, + 'proccessed_content' => $this->processed_content, + 'total_content' => $this->total_content, + ]; + } +} diff --git a/app/Jobs/FixPolygonOverlapJob.php b/app/Jobs/FixPolygonOverlapJob.php index 6196c339e..a272f8693 100644 --- a/app/Jobs/FixPolygonOverlapJob.php +++ b/app/Jobs/FixPolygonOverlapJob.php @@ -4,6 +4,7 @@ use App\Http\Middleware\SetAuthenticatedUserForJob; use App\Models\DelayedJob; +use App\Models\DelayedJobProgress; use App\Services\PolygonService; use Exception; use Illuminate\Bus\Queueable; @@ -63,14 +64,15 @@ public function handle(): void { try { - $delayedJob = DelayedJob::findOrFail($this->delayed_job_id); + $delayedJob = DelayedJobProgress::findOrFail($this->delayed_job_id); $user = Auth::user(); if ($user) { - $polygonsClipped = App::make(PolygonService::class)->processClippedPolygons($this->polygonUuids); + $polygonsClipped = App::make(PolygonService::class)->processClippedPolygons($this->polygonUuids, $this->delayed_job_id); $delayedJob->update([ - 'status' => DelayedJob::STATUS_SUCCEEDED, + 'status' => DelayedJobProgress::STATUS_SUCCEEDED, 'payload' => json_encode(['updated_polygons' => $polygonsClipped]), 'status_code' => Response::HTTP_OK, + 'progress' => 100, ]); } } catch (Exception $e) { diff --git a/app/Jobs/RunSitePolygonsValidationJob.php b/app/Jobs/RunSitePolygonsValidationJob.php index 96fe5e6f5..c3a275fc1 100644 --- a/app/Jobs/RunSitePolygonsValidationJob.php +++ b/app/Jobs/RunSitePolygonsValidationJob.php @@ -3,6 +3,7 @@ namespace App\Jobs; use App\Models\DelayedJob; +use App\Models\DelayedJobProgress; use App\Services\PolygonValidationService; use Exception; use Illuminate\Bus\Queueable; @@ -48,7 +49,7 @@ public function __construct(string $delayed_job_id, array $sitePolygonsUuids) public function handle(PolygonValidationService $validationService) { try { - $delayedJob = DelayedJob::findOrFail($this->delayed_job_id); + $delayedJob = DelayedJobProgress::findOrFail($this->delayed_job_id); foreach ($this->sitePolygonsUuids as $polygonUuid) { $request = new Request(['uuid' => $polygonUuid]); $validationService->validateOverlapping($request); @@ -60,12 +61,17 @@ public function handle(PolygonValidationService $validationService) $validationService->getGeometryType($request); $validationService->validateEstimatedArea($request); $validationService->validateDataInDB($request); + + $delayedJob->increment('processed_content'); + $delayedJob->calculateProgress(); + $delayedJob->save(); } $delayedJob->update([ - 'status' => DelayedJob::STATUS_SUCCEEDED, + 'status' => DelayedJobProgress::STATUS_SUCCEEDED, 'payload' => ['message' => 'Validation completed for all site polygons'], 'status_code' => Response::HTTP_OK, + 'progress' => 100, ]); } catch (Exception $e) { diff --git a/app/Models/DelayedJobProgress.php b/app/Models/DelayedJobProgress.php new file mode 100644 index 000000000..a8cb5bc5a --- /dev/null +++ b/app/Models/DelayedJobProgress.php @@ -0,0 +1,38 @@ +fillable = array_merge($this->fillable, [ + 'progress', + 'processed_content', + 'total_content', + ]); + + $this->casts = array_merge($this->casts, [ + 'progress' => 'integer', + 'processed_content' => 'integer', + 'total_content' => 'integer', + ]); + } + + /** + * Calculate the progress percentage as an integer. + * + * @return int + */ + public function calculateProgress(): int + { + if ($this->total_content > 0) { + $this->progress = (int)(($this->processed_content / $this->total_content) * 100); + } else { + $this->progress = 0; + } + return $this->progress; + } +} diff --git a/app/Services/PolygonService.php b/app/Services/PolygonService.php index c6712bb77..de3f7c1d8 100755 --- a/app/Services/PolygonService.php +++ b/app/Services/PolygonService.php @@ -26,6 +26,7 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use InvalidArgumentException; +use App\Models\DelayedJobProgress; class PolygonService { @@ -562,13 +563,16 @@ public function insertGeojsonToDBFromContent(string $geojsonData, ?string $entit } } - public function processClippedPolygons(array $polygonUuids) + public function processClippedPolygons(array $polygonUuids, $delayed_job_id = null) { $geojson = GeometryHelper::getPolygonsGeojson($polygonUuids); $clippedPolygons = App::make(PythonService::class)->clipPolygons($geojson); $uuids = []; + $delayedJob = DelayedJobProgress::findOrFail($delayed_job_id); + + Log::info("test"); if (isset($clippedPolygons['type']) && $clippedPolygons['type'] === 'FeatureCollection' && isset($clippedPolygons['features'])) { foreach ($clippedPolygons['features'] as $feature) { if (isset($feature['properties']['poly_id'])) { @@ -593,6 +597,9 @@ public function processClippedPolygons(array $polygonUuids) if (! empty($uuids)) { foreach ($newPolygonUuids as $polygonUuid) { App::make(PolygonValidationService::class)->runValidationPolygon($polygonUuid); + $delayedJob->increment('processed_content'); + $delayedJob->calculateProgress(); + $delayedJob->save(); } } diff --git a/database/migrations/2024_11_27_103000_add_fields_to_delayed_job_table.php b/database/migrations/2024_11_27_103000_add_fields_to_delayed_job_table.php new file mode 100644 index 000000000..248e84f3d --- /dev/null +++ b/database/migrations/2024_11_27_103000_add_fields_to_delayed_job_table.php @@ -0,0 +1,33 @@ +unsignedTinyInteger('progress')->nullable()->after('payload'); + $table->unsignedInteger('processed_content')->nullable()->after('progress'); + $table->unsignedInteger('total_content')->nullable()->after('processed_content'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('delayed_jobs', function (Blueprint $table) { + $table->dropColumn(['progress', 'proccessed_content', 'total_content']); + }); + } +}; From 245dc1eeabf5ace99d1b86c301674d71574581ca Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 03:12:39 -0400 Subject: [PATCH 2/8] remove progress field --- .../Resources/DelayedJobProgressResource.php | 1 - app/Jobs/RunSitePolygonsValidationJob.php | 1 - app/Models/DelayedJobProgress.php | 17 ----------------- app/Services/PolygonService.php | 1 - ...7_103000_add_fields_to_delayed_job_table.php | 5 ++--- 5 files changed, 2 insertions(+), 23 deletions(-) diff --git a/app/Http/Resources/DelayedJobProgressResource.php b/app/Http/Resources/DelayedJobProgressResource.php index 21984bca1..6f6accdd2 100644 --- a/app/Http/Resources/DelayedJobProgressResource.php +++ b/app/Http/Resources/DelayedJobProgressResource.php @@ -17,7 +17,6 @@ public function toArray(Request $request): array return [ 'message' => $this->message ?? 'Job dispatched', 'job_uuid' => $this->uuid, - 'progress' => $this->progress, 'proccessed_content' => $this->processed_content, 'total_content' => $this->total_content, ]; diff --git a/app/Jobs/RunSitePolygonsValidationJob.php b/app/Jobs/RunSitePolygonsValidationJob.php index c3a275fc1..18d91e2f0 100644 --- a/app/Jobs/RunSitePolygonsValidationJob.php +++ b/app/Jobs/RunSitePolygonsValidationJob.php @@ -63,7 +63,6 @@ public function handle(PolygonValidationService $validationService) $validationService->validateDataInDB($request); $delayedJob->increment('processed_content'); - $delayedJob->calculateProgress(); $delayedJob->save(); } diff --git a/app/Models/DelayedJobProgress.php b/app/Models/DelayedJobProgress.php index a8cb5bc5a..d7e6aefc6 100644 --- a/app/Models/DelayedJobProgress.php +++ b/app/Models/DelayedJobProgress.php @@ -9,30 +9,13 @@ public function __construct(array $attributes = []) parent::__construct($attributes); $this->fillable = array_merge($this->fillable, [ - 'progress', 'processed_content', 'total_content', ]); $this->casts = array_merge($this->casts, [ - 'progress' => 'integer', 'processed_content' => 'integer', 'total_content' => 'integer', ]); } - - /** - * Calculate the progress percentage as an integer. - * - * @return int - */ - public function calculateProgress(): int - { - if ($this->total_content > 0) { - $this->progress = (int)(($this->processed_content / $this->total_content) * 100); - } else { - $this->progress = 0; - } - return $this->progress; - } } diff --git a/app/Services/PolygonService.php b/app/Services/PolygonService.php index de3f7c1d8..20a1e8ef4 100755 --- a/app/Services/PolygonService.php +++ b/app/Services/PolygonService.php @@ -598,7 +598,6 @@ public function processClippedPolygons(array $polygonUuids, $delayed_job_id = nu foreach ($newPolygonUuids as $polygonUuid) { App::make(PolygonValidationService::class)->runValidationPolygon($polygonUuid); $delayedJob->increment('processed_content'); - $delayedJob->calculateProgress(); $delayedJob->save(); } } diff --git a/database/migrations/2024_11_27_103000_add_fields_to_delayed_job_table.php b/database/migrations/2024_11_27_103000_add_fields_to_delayed_job_table.php index 248e84f3d..824fe6650 100644 --- a/database/migrations/2024_11_27_103000_add_fields_to_delayed_job_table.php +++ b/database/migrations/2024_11_27_103000_add_fields_to_delayed_job_table.php @@ -13,8 +13,7 @@ public function up() { Schema::table('delayed_jobs', function (Blueprint $table) { - $table->unsignedTinyInteger('progress')->nullable()->after('payload'); - $table->unsignedInteger('processed_content')->nullable()->after('progress'); + $table->unsignedInteger('processed_content')->nullable()->after('payload'); $table->unsignedInteger('total_content')->nullable()->after('processed_content'); }); } @@ -27,7 +26,7 @@ public function up() public function down() { Schema::table('delayed_jobs', function (Blueprint $table) { - $table->dropColumn(['progress', 'proccessed_content', 'total_content']); + $table->dropColumn(['proccessed_content', 'total_content']); }); } }; From 6fcce2ba0b5f73b4b0a6db192ee0fe7646bec471 Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 03:52:00 -0400 Subject: [PATCH 3/8] fix lint --- .../V2/Terrafund/TerrafundClipGeometryController.php | 8 -------- .../V2/Terrafund/TerrafundCreateGeometryController.php | 4 +--- app/Http/Resources/DelayedJobProgressResource.php | 2 +- app/Jobs/FixPolygonOverlapJob.php | 1 + app/Services/PolygonService.php | 6 ++++-- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php index 7d23cb08b..f1180a417 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php @@ -4,9 +4,7 @@ use App\Helpers\GeometryHelper; use App\Http\Resources\DelayedJobResource; -use App\Http\Resources\DelayedJobProgressResource; use App\Jobs\FixPolygonOverlapJob; -use App\Models\DelayedJob; use App\Models\DelayedJobProgress; use App\Models\V2\Sites\CriteriaSite; use App\Models\V2\Sites\Site; @@ -29,9 +27,7 @@ public function clipOverlappingPolygonsBySite(string $uuid) $user = Auth::user(); $polygonUuids = GeometryHelper::getSitePolygonsUuids($uuid)->toArray(); $delayedJob = DelayedJobProgress::create([ - 'total_content' => count($polygonUuids), 'processed_content' => 0, - 'progress' => 0, ]); $job = new FixPolygonOverlapJob($delayedJob->id, $polygonUuids, $user->id); dispatch($job); @@ -49,9 +45,7 @@ public function clipOverlappingPolygonsOfProjectBySite(string $uuid) $projectId = $sitePolygon->project_id ?? null; $polygonUuids = GeometryHelper::getProjectPolygonsUuids($projectId); $delayedJob = DelayedJobProgress::create([ - 'total_content' => count($polygonUuids), 'processed_content' => 0, - 'progress' => 0, ]); $job = new FixPolygonOverlapJob($delayedJob->id, $polygonUuids, $user->id); dispatch($job); @@ -101,9 +95,7 @@ public function clipOverlappingPolygons(Request $request) if (! empty($uniquePolygonUuids)) { $user = Auth::user(); $delayedJob = DelayedJobProgress::create([ - 'total_content' => count($uniquePolygonUuids), 'processed_content' => 0, - 'progress' => 0, ]); $job = new FixPolygonOverlapJob($delayedJob->id, $polygonUuids, $user->id); dispatch($job); diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php index 5f5aa7ada..cfc5e37dc 100755 --- a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php @@ -1207,7 +1207,7 @@ public function runValidationPolygon(string $uuid) public function sendRunValidationPolygon(Request $request) { - Log::info("here criteria data"); + Log::info('here criteria data'); $uuid = $request->input('uuid'); $this->runValidationPolygon($uuid); $criteriaData = $this->getCriteriaData($request); @@ -1224,7 +1224,6 @@ public function runSiteValidationPolygon(Request $request) $delayedJob = DelayedJobProgress::create([ 'total_content' => count($sitePolygonsUuids), 'processed_content' => 0, - 'progress' => 0, ]); $job = new RunSitePolygonsValidationJob($delayedJob->id, $sitePolygonsUuids); dispatch($job); @@ -1244,7 +1243,6 @@ public function runPolygonsValidation(Request $request) $delayedJob = DelayedJobProgress::create([ 'total_content' => count($uuids), 'processed_content' => 0, - 'progress' => 0, ]); $job = new RunSitePolygonsValidationJob($delayedJob->id, $uuids); dispatch($job); diff --git a/app/Http/Resources/DelayedJobProgressResource.php b/app/Http/Resources/DelayedJobProgressResource.php index 6f6accdd2..df722ab52 100644 --- a/app/Http/Resources/DelayedJobProgressResource.php +++ b/app/Http/Resources/DelayedJobProgressResource.php @@ -18,7 +18,7 @@ public function toArray(Request $request): array 'message' => $this->message ?? 'Job dispatched', 'job_uuid' => $this->uuid, 'proccessed_content' => $this->processed_content, - 'total_content' => $this->total_content, + 'total_content' => $this->total_content, ]; } } diff --git a/app/Jobs/FixPolygonOverlapJob.php b/app/Jobs/FixPolygonOverlapJob.php index a272f8693..0150a14fe 100644 --- a/app/Jobs/FixPolygonOverlapJob.php +++ b/app/Jobs/FixPolygonOverlapJob.php @@ -62,6 +62,7 @@ public function middleware() */ public function handle(): void { + Log::info('all plygon fix'); try { $delayedJob = DelayedJobProgress::findOrFail($this->delayed_job_id); diff --git a/app/Services/PolygonService.php b/app/Services/PolygonService.php index 20a1e8ef4..d6c53b033 100755 --- a/app/Services/PolygonService.php +++ b/app/Services/PolygonService.php @@ -5,6 +5,7 @@ use App\Helpers\CreateVersionPolygonGeometryHelper; use App\Helpers\GeometryHelper; use App\Helpers\PolygonGeometryHelper; +use App\Models\DelayedJobProgress; use App\Models\V2\PointGeometry; use App\Models\V2\PolygonGeometry; use App\Models\V2\ProjectPitch; @@ -26,7 +27,6 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use InvalidArgumentException; -use App\Models\DelayedJobProgress; class PolygonService { @@ -572,7 +572,7 @@ public function processClippedPolygons(array $polygonUuids, $delayed_job_id = nu $delayedJob = DelayedJobProgress::findOrFail($delayed_job_id); - Log::info("test"); + Log::info('test now selected plygons'); if (isset($clippedPolygons['type']) && $clippedPolygons['type'] === 'FeatureCollection' && isset($clippedPolygons['features'])) { foreach ($clippedPolygons['features'] as $feature) { if (isset($feature['properties']['poly_id'])) { @@ -595,6 +595,8 @@ public function processClippedPolygons(array $polygonUuids, $delayed_job_id = nu } if (! empty($uuids)) { + $delayedJob->total_content = count($newPolygonUuids); + $delayedJob->save(); foreach ($newPolygonUuids as $polygonUuid) { App::make(PolygonValidationService::class)->runValidationPolygon($polygonUuid); $delayedJob->increment('processed_content'); From 2b38e0afcc95585dc73eac45701fd04555fae53c Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 09:48:51 -0400 Subject: [PATCH 4/8] [TM-1536] add optional attribute --- app/Services/PolygonService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Services/PolygonService.php b/app/Services/PolygonService.php index d6c53b033..98760a7fb 100755 --- a/app/Services/PolygonService.php +++ b/app/Services/PolygonService.php @@ -563,7 +563,7 @@ public function insertGeojsonToDBFromContent(string $geojsonData, ?string $entit } } - public function processClippedPolygons(array $polygonUuids, $delayed_job_id = null) + public function processClippedPolygons(array $polygonUuids, ?string $delayed_job_id = null) { $geojson = GeometryHelper::getPolygonsGeojson($polygonUuids); From da25d6c21f04120136f6e7e14976a18433c35211 Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 09:55:22 -0400 Subject: [PATCH 5/8] remove comments --- .../V2/Terrafund/TerrafundClipGeometryController.php | 1 - .../V2/Terrafund/TerrafundCreateGeometryController.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php index f1180a417..d13b63a3d 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundClipGeometryController.php @@ -21,7 +21,6 @@ class TerrafundClipGeometryController extends TerrafundCreateGeometryController public function clipOverlappingPolygonsBySite(string $uuid) { - Log::info('Clipping polygons by site', ['uuid' => $uuid]); ini_set('max_execution_time', self::MAX_EXECUTION_TIME); ini_set('memory_limit', '-1'); $user = Auth::user(); diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php index cfc5e37dc..2d294338f 100755 --- a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php @@ -893,7 +893,6 @@ function ($attribute, $value, $fail) { public function validateOverlapping(Request $request) { - Log::info('overlapping validation request'); $uuid = $request->input('uuid'); return $this->handlePolygonValidation( @@ -1207,7 +1206,6 @@ public function runValidationPolygon(string $uuid) public function sendRunValidationPolygon(Request $request) { - Log::info('here criteria data'); $uuid = $request->input('uuid'); $this->runValidationPolygon($uuid); $criteriaData = $this->getCriteriaData($request); From 2d2c0fe1202bdebbb21e41c70292019e96c9f7af Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 10:29:08 -0400 Subject: [PATCH 6/8] remove comments --- .../V2/Terrafund/TerrafundCreateGeometryController.php | 1 + app/Jobs/FixPolygonOverlapJob.php | 1 - app/Services/PolygonService.php | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php index 2d294338f..dab1bddbb 100755 --- a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php @@ -1206,6 +1206,7 @@ public function runValidationPolygon(string $uuid) public function sendRunValidationPolygon(Request $request) { + $uuid = $request->input('uuid'); $this->runValidationPolygon($uuid); $criteriaData = $this->getCriteriaData($request); diff --git a/app/Jobs/FixPolygonOverlapJob.php b/app/Jobs/FixPolygonOverlapJob.php index 0150a14fe..a272f8693 100644 --- a/app/Jobs/FixPolygonOverlapJob.php +++ b/app/Jobs/FixPolygonOverlapJob.php @@ -62,7 +62,6 @@ public function middleware() */ public function handle(): void { - Log::info('all plygon fix'); try { $delayedJob = DelayedJobProgress::findOrFail($this->delayed_job_id); diff --git a/app/Services/PolygonService.php b/app/Services/PolygonService.php index 98760a7fb..d6c53b033 100755 --- a/app/Services/PolygonService.php +++ b/app/Services/PolygonService.php @@ -563,7 +563,7 @@ public function insertGeojsonToDBFromContent(string $geojsonData, ?string $entit } } - public function processClippedPolygons(array $polygonUuids, ?string $delayed_job_id = null) + public function processClippedPolygons(array $polygonUuids, $delayed_job_id = null) { $geojson = GeometryHelper::getPolygonsGeojson($polygonUuids); From 89614995822707ff5e321c1de41dd7a1ebdc65a7 Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 13:05:47 -0400 Subject: [PATCH 7/8] [TM-1536] add proccess message field --- app/Http/Resources/DelayedJobProgressResource.php | 1 + app/Jobs/RunSitePolygonsValidationJob.php | 1 + app/Models/DelayedJobProgress.php | 14 ++++++++++++++ app/Services/PolygonService.php | 1 + ...1_27_103000_add_fields_to_delayed_job_table.php | 3 ++- 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/Http/Resources/DelayedJobProgressResource.php b/app/Http/Resources/DelayedJobProgressResource.php index df722ab52..206b35f25 100644 --- a/app/Http/Resources/DelayedJobProgressResource.php +++ b/app/Http/Resources/DelayedJobProgressResource.php @@ -19,6 +19,7 @@ public function toArray(Request $request): array 'job_uuid' => $this->uuid, 'proccessed_content' => $this->processed_content, 'total_content' => $this->total_content, + 'proccess_message' => $this->proccess_message ]; } } diff --git a/app/Jobs/RunSitePolygonsValidationJob.php b/app/Jobs/RunSitePolygonsValidationJob.php index 18d91e2f0..9bba9777c 100644 --- a/app/Jobs/RunSitePolygonsValidationJob.php +++ b/app/Jobs/RunSitePolygonsValidationJob.php @@ -63,6 +63,7 @@ public function handle(PolygonValidationService $validationService) $validationService->validateDataInDB($request); $delayedJob->increment('processed_content'); + $delayedJob->processMessage(); $delayedJob->save(); } diff --git a/app/Models/DelayedJobProgress.php b/app/Models/DelayedJobProgress.php index d7e6aefc6..0eb3106f4 100644 --- a/app/Models/DelayedJobProgress.php +++ b/app/Models/DelayedJobProgress.php @@ -11,11 +11,25 @@ public function __construct(array $attributes = []) $this->fillable = array_merge($this->fillable, [ 'processed_content', 'total_content', + 'proccess_message' ]); $this->casts = array_merge($this->casts, [ 'processed_content' => 'integer', 'total_content' => 'integer', + 'proccess_message' => 'string' ]); } + + public function processMessage(): string + { + $progress = 0; + if ($this->total_content > 0) { + $progress = (int)(($this->processed_content / $this->total_content) * 100); + } else { + $progress = 0; + } + return $this->proccess_message = 'Running '. $this->processed_content .' out of ' + .$this->total_content. ' polygons ('.$progress.'%)' ; + } } diff --git a/app/Services/PolygonService.php b/app/Services/PolygonService.php index d6c53b033..5213b9af9 100755 --- a/app/Services/PolygonService.php +++ b/app/Services/PolygonService.php @@ -600,6 +600,7 @@ public function processClippedPolygons(array $polygonUuids, $delayed_job_id = nu foreach ($newPolygonUuids as $polygonUuid) { App::make(PolygonValidationService::class)->runValidationPolygon($polygonUuid); $delayedJob->increment('processed_content'); + $delayedJob->processMessage(); $delayedJob->save(); } } diff --git a/database/migrations/2024_11_27_103000_add_fields_to_delayed_job_table.php b/database/migrations/2024_11_27_103000_add_fields_to_delayed_job_table.php index 824fe6650..c537ca063 100644 --- a/database/migrations/2024_11_27_103000_add_fields_to_delayed_job_table.php +++ b/database/migrations/2024_11_27_103000_add_fields_to_delayed_job_table.php @@ -15,6 +15,7 @@ public function up() Schema::table('delayed_jobs', function (Blueprint $table) { $table->unsignedInteger('processed_content')->nullable()->after('payload'); $table->unsignedInteger('total_content')->nullable()->after('processed_content'); + $table->string('proccess_message')->nullable()->after('total_content'); }); } @@ -26,7 +27,7 @@ public function up() public function down() { Schema::table('delayed_jobs', function (Blueprint $table) { - $table->dropColumn(['proccessed_content', 'total_content']); + $table->dropColumn(['proccessed_content', 'total_content', 'proccess_message']); }); } }; From 09f671f470f7f85bd4fdc1a1bc9f41baff3592c4 Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 13:37:02 -0400 Subject: [PATCH 8/8] [TM-1536] fix lint --- app/Http/Resources/DelayedJobProgressResource.php | 2 +- app/Models/DelayedJobProgress.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Http/Resources/DelayedJobProgressResource.php b/app/Http/Resources/DelayedJobProgressResource.php index 206b35f25..234c2ad8b 100644 --- a/app/Http/Resources/DelayedJobProgressResource.php +++ b/app/Http/Resources/DelayedJobProgressResource.php @@ -19,7 +19,7 @@ public function toArray(Request $request): array 'job_uuid' => $this->uuid, 'proccessed_content' => $this->processed_content, 'total_content' => $this->total_content, - 'proccess_message' => $this->proccess_message + 'proccess_message' => $this->proccess_message, ]; } } diff --git a/app/Models/DelayedJobProgress.php b/app/Models/DelayedJobProgress.php index 0eb3106f4..a01fda4f2 100644 --- a/app/Models/DelayedJobProgress.php +++ b/app/Models/DelayedJobProgress.php @@ -11,13 +11,13 @@ public function __construct(array $attributes = []) $this->fillable = array_merge($this->fillable, [ 'processed_content', 'total_content', - 'proccess_message' + 'proccess_message', ]); $this->casts = array_merge($this->casts, [ 'processed_content' => 'integer', 'total_content' => 'integer', - 'proccess_message' => 'string' + 'proccess_message' => 'string', ]); } @@ -29,7 +29,8 @@ public function processMessage(): string } else { $progress = 0; } - return $this->proccess_message = 'Running '. $this->processed_content .' out of ' + + return $this->proccess_message = 'Running '. $this->processed_content .' out of ' .$this->total_content. ' polygons ('.$progress.'%)' ; } }