-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TM-1536] add delayed job progress (#593)
* [TM-1536] add delayed job progress * remove progress field * fix lint * [TM-1536] add optional attribute * remove comments * remove comments * [TM-1536] add proccess message field * [TM-1536] fix lint
- Loading branch information
1 parent
7873ac9
commit 1c2c749
Showing
8 changed files
with
137 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class DelayedJobProgressResource extends JsonResource | ||
{ | ||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(Request $request): array | ||
{ | ||
return [ | ||
'message' => $this->message ?? 'Job dispatched', | ||
'job_uuid' => $this->uuid, | ||
'proccessed_content' => $this->processed_content, | ||
'total_content' => $this->total_content, | ||
'proccess_message' => $this->proccess_message, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
class DelayedJobProgress extends DelayedJob | ||
{ | ||
public function __construct(array $attributes = []) | ||
{ | ||
parent::__construct($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.'%)' ; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
database/migrations/2024_11_27_103000_add_fields_to_delayed_job_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration { | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
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'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('delayed_jobs', function (Blueprint $table) { | ||
$table->dropColumn(['proccessed_content', 'total_content', 'proccess_message']); | ||
}); | ||
} | ||
}; |