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) {
|
->formatStateUsing(fn (string $state): string => match ($state) {
|
||||||
'pending' => 'várakozik',
|
'pending' => 'várakozik',
|
||||||
'inprogress' => 'folyamatban',
|
'inprogress' => 'folyamatban',
|
||||||
'done' => 'kész',
|
'completed' => 'kész',
|
||||||
'fail' => 'hiba',
|
'failed' => 'hiba',
|
||||||
default => $state,
|
default => $state,
|
||||||
})
|
})
|
||||||
->color(fn (string $state): string => match ($state) {
|
->color(fn (string $state): string => match ($state) {
|
||||||
'pending' => 'gray',
|
'pending' => 'gray',
|
||||||
'inprogress' => 'info',
|
'inprogress' => 'info',
|
||||||
'done' => 'success',
|
'completed' => 'success',
|
||||||
'fail' => 'danger',
|
'failed' => 'danger',
|
||||||
default => 'gray',
|
default => 'gray',
|
||||||
})
|
})
|
||||||
->icon(fn (string $state): string => match ($state) {
|
->icon(fn (string $state): string => match ($state) {
|
||||||
'pending' => 'heroicon-o-clock',
|
'pending' => 'heroicon-o-clock',
|
||||||
'inprogress' => 'heroicon-o-arrow-path',
|
'inprogress' => 'heroicon-o-arrow-path',
|
||||||
'done' => 'heroicon-o-check-circle',
|
'completed' => 'heroicon-o-check-circle',
|
||||||
'fail' => 'heroicon-o-x-circle',
|
'failed' => 'heroicon-o-x-circle',
|
||||||
default => 'heroicon-o-question-mark-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(
|
public function updateStepStatus(
|
||||||
PricelistFile $pricelistFile,
|
PricelistFile $pricelistFile,
|
||||||
PricelistWorkflowStep $stepEnum,
|
PricelistWorkflowStep $stepEnum,
|
||||||
string $status,
|
string $status,
|
||||||
?string $message = null,
|
?string $message = null,
|
||||||
int $percentage = 0
|
?int $percentage = 0
|
||||||
): void {
|
): void {
|
||||||
$effectiveMessage = $message ?? $stepEnum->label();
|
$effectiveMessage = $message ?? $stepEnum->label();
|
||||||
|
|
||||||
// Frissítjük a modellt az adatbázisból, hogy a legfrissebb workflow_steps-szel dolgozzunk
|
// 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) {
|
if ($pricelistFile->exists) {
|
||||||
$pricelistFile->refresh();
|
$pricelistFile->refresh();
|
||||||
}
|
}
|
||||||
@ -87,7 +83,13 @@ public function updateStepStatus(
|
|||||||
];
|
];
|
||||||
|
|
||||||
if ($status === 'inprogress') {
|
if ($status === 'inprogress') {
|
||||||
$updateData['status'] = PricelistFileStatusEnum::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') {
|
} elseif ($status === 'failed') {
|
||||||
$updateData['status'] = PricelistFileStatusEnum::fail;
|
$updateData['status'] = PricelistFileStatusEnum::fail;
|
||||||
}
|
}
|
||||||
@ -130,18 +132,18 @@ public function preProcess(PricelistFile $pricelistFile): bool
|
|||||||
*/
|
*/
|
||||||
public function validate(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);
|
$this->updateStepStatus($pricelistFile, PricelistWorkflowStep::Validation, 'inprogress', 'Üzleti szabályok ellenőrzése...', 60);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO: Validációs logika
|
// TODO: Validációs logika
|
||||||
sleep(1); // Szimuláció
|
sleep(15); // Szimuláció
|
||||||
|
|
||||||
$this->updateStepStatus($pricelistFile, PricelistWorkflowStep::Validation, 'completed', 'Validálás sikeres.', 100);
|
$this->updateStepStatus($pricelistFile, PricelistWorkflowStep::Validation, 'completed', 'Validálás sikeres.', 100);
|
||||||
|
|
||||||
$pricelistFile->update([
|
sleep(15); // Szimuláció
|
||||||
'status' => PricelistFileStatusEnum::waiting_for_approval,
|
// A validálás végén átadjuk a lépést a jóváhagyásnak (Approval)
|
||||||
'processing_current_step' => 'Előfeldolgozás és validálás kész, jóváhagyásra vár.',
|
$this->updateStepStatus($pricelistFile, PricelistWorkflowStep::Approval, 'inprogress');
|
||||||
]);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} 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