fix workflow step status and percentage progress
This commit is contained in:
parent
6c430afffe
commit
67c108eeca
@ -77,22 +77,22 @@ public static function configure(Schema $schema): Schema
|
||||
->formatStateUsing(fn (string $state): string => match ($state) {
|
||||
'pending' => 'várakozik',
|
||||
'inprogress' => 'folyamatban',
|
||||
'done' => 'kész',
|
||||
'fail' => 'hiba',
|
||||
'completed' => 'kész',
|
||||
'failed' => 'hiba',
|
||||
default => $state,
|
||||
})
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'pending' => 'gray',
|
||||
'inprogress' => 'info',
|
||||
'done' => 'success',
|
||||
'fail' => 'danger',
|
||||
'completed' => 'success',
|
||||
'failed' => 'danger',
|
||||
default => 'gray',
|
||||
})
|
||||
->icon(fn (string $state): string => match ($state) {
|
||||
'pending' => 'heroicon-o-clock',
|
||||
'inprogress' => 'heroicon-o-arrow-path',
|
||||
'done' => 'heroicon-o-check-circle',
|
||||
'fail' => 'heroicon-o-x-circle',
|
||||
'completed' => 'heroicon-o-check-circle',
|
||||
'failed' => 'heroicon-o-x-circle',
|
||||
default => 'heroicon-o-question-mark-circle',
|
||||
}),
|
||||
])
|
||||
|
||||
@ -37,20 +37,16 @@ public function dispatchExecutionJob(PricelistFile $pricelistFile): void
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frissíti egy workflow lépés állapotát és az aktuális folyamat jelzőket
|
||||
*/
|
||||
public function updateStepStatus(
|
||||
PricelistFile $pricelistFile,
|
||||
PricelistWorkflowStep $stepEnum,
|
||||
string $status,
|
||||
?string $message = null,
|
||||
int $percentage = 0
|
||||
?int $percentage = 0
|
||||
): void {
|
||||
$effectiveMessage = $message ?? $stepEnum->label();
|
||||
|
||||
// Frissítjük a modellt az adatbázisból, hogy a legfrissebb workflow_steps-szel dolgozzunk
|
||||
// Ez különösen fontos a láncolt joboknál (Bus::chain), ahol az objektum "stale" maradhat a sorban következő job számára
|
||||
if ($pricelistFile->exists) {
|
||||
$pricelistFile->refresh();
|
||||
}
|
||||
@ -87,7 +83,13 @@ public function updateStepStatus(
|
||||
];
|
||||
|
||||
if ($status === 'inprogress') {
|
||||
if ($stepEnum === PricelistWorkflowStep::Approval) {
|
||||
$updateData['status'] = PricelistFileStatusEnum::waiting_for_approval;
|
||||
$updateData['processing_current_step'] = null;
|
||||
$updateData['processing_current_step_percentage'] = null;
|
||||
} else {
|
||||
$updateData['status'] = PricelistFileStatusEnum::inprogress;
|
||||
}
|
||||
} elseif ($status === 'failed') {
|
||||
$updateData['status'] = PricelistFileStatusEnum::fail;
|
||||
}
|
||||
@ -130,18 +132,18 @@ public function preProcess(PricelistFile $pricelistFile): bool
|
||||
*/
|
||||
public function validate(PricelistFile $pricelistFile): bool
|
||||
{
|
||||
sleep(15); // Szimuláció
|
||||
$this->updateStepStatus($pricelistFile, PricelistWorkflowStep::Validation, 'inprogress', 'Üzleti szabályok ellenőrzése...', 60);
|
||||
|
||||
try {
|
||||
// TODO: Validációs logika
|
||||
sleep(1); // Szimuláció
|
||||
sleep(15); // Szimuláció
|
||||
|
||||
$this->updateStepStatus($pricelistFile, PricelistWorkflowStep::Validation, 'completed', 'Validálás sikeres.', 100);
|
||||
|
||||
$pricelistFile->update([
|
||||
'status' => PricelistFileStatusEnum::waiting_for_approval,
|
||||
'processing_current_step' => 'Előfeldolgozás és validálás kész, jóváhagyásra vár.',
|
||||
]);
|
||||
sleep(15); // Szimuláció
|
||||
// A validálás végén átadjuk a lépést a jóváhagyásnak (Approval)
|
||||
$this->updateStepStatus($pricelistFile, PricelistWorkflowStep::Approval, 'inprogress');
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\PricelistFileStatusEnum;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('pricelist_files', function (Blueprint $table) {
|
||||
$table->enum('status', array_column(PricelistFileStatusEnum::cases(), 'value'))
|
||||
->default(PricelistFileStatusEnum::todo->value)
|
||||
->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('pricelist_files', function (Blueprint $table) {
|
||||
$table->enum('status', ['todo', 'inprogress', 'fail', 'done', 'closed'])
|
||||
->default(PricelistFileStatusEnum::todo->value)
|
||||
->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user