68 lines
1.7 KiB
PHP
68 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
class ProcessingLog extends Model
|
|
{
|
|
const UPDATED_AT = null;
|
|
|
|
protected $fillable = [
|
|
'processable_type',
|
|
'processable_id',
|
|
'stage',
|
|
'status',
|
|
'message',
|
|
'metadata',
|
|
'duration',
|
|
];
|
|
|
|
protected $casts = [
|
|
'metadata' => 'array',
|
|
'duration' => 'float',
|
|
];
|
|
|
|
const STAGE_UPLOAD = 'upload';
|
|
const STAGE_EXTRACT = 'extract';
|
|
const STAGE_CHUNK = 'chunk';
|
|
const STAGE_EMBED = 'embed';
|
|
const STAGE_QDRANT = 'qdrant_sync';
|
|
const STAGE_COMPLETE = 'completed';
|
|
const STAGE_FAILED = 'failed';
|
|
|
|
const STATUS_STARTED = 'started';
|
|
const STATUS_COMPLETED = 'completed';
|
|
const STATUS_FAILED = 'failed';
|
|
|
|
public function scopeForRecord(Builder $query, string $type, int $id): Builder
|
|
{
|
|
return $query->where('processable_type', $type)
|
|
->where('processable_id', $id);
|
|
}
|
|
|
|
/**
|
|
* Helper untuk log processing dengan masa
|
|
*/
|
|
public static function record(
|
|
string $type,
|
|
int $id,
|
|
string $stage,
|
|
string $status,
|
|
?string $message = null,
|
|
?array $metadata = null,
|
|
?float $duration = null
|
|
): self {
|
|
return static::create([
|
|
'processable_type' => $type,
|
|
'processable_id' => $id,
|
|
'stage' => $stage,
|
|
'status' => $status,
|
|
'message' => $message,
|
|
'metadata' => $metadata,
|
|
'duration' => $duration,
|
|
]);
|
|
}
|
|
}
|