gutendex processing implementation
This commit is contained in:
@@ -10,8 +10,22 @@ class Summary extends Model
|
||||
'content',
|
||||
'key_insights',
|
||||
'book_id',
|
||||
'processing_status',
|
||||
'processing_error',
|
||||
'processed_at',
|
||||
'model_used',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'processed_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the book that owns the summary.
|
||||
*/
|
||||
@@ -19,4 +33,79 @@ class Summary extends Model
|
||||
{
|
||||
return $this->belongsTo(Book::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include summaries with a specific status.
|
||||
*/
|
||||
public function scopeWithStatus($query, string $status)
|
||||
{
|
||||
return $query->where('processing_status', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include pending summaries.
|
||||
*/
|
||||
public function scopePending($query)
|
||||
{
|
||||
return $query->where('processing_status', 'pending');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include processing summaries.
|
||||
*/
|
||||
public function scopeProcessing($query)
|
||||
{
|
||||
return $query->where('processing_status', 'processing');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include completed summaries.
|
||||
*/
|
||||
public function scopeCompleted($query)
|
||||
{
|
||||
return $query->where('processing_status', 'completed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include failed summaries.
|
||||
*/
|
||||
public function scopeFailed($query)
|
||||
{
|
||||
return $query->where('processing_status', 'failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the summary as processing.
|
||||
*/
|
||||
public function markAsProcessing(): void
|
||||
{
|
||||
$this->update([
|
||||
'processing_status' => 'processing',
|
||||
'processing_error' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the summary as completed.
|
||||
*/
|
||||
public function markAsCompleted(string $modelUsed): void
|
||||
{
|
||||
$this->update([
|
||||
'processing_status' => 'completed',
|
||||
'processing_error' => null,
|
||||
'processed_at' => now(),
|
||||
'model_used' => $modelUsed,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the summary as failed with an error message.
|
||||
*/
|
||||
public function markAsFailed(string $error): void
|
||||
{
|
||||
$this->update([
|
||||
'processing_status' => 'failed',
|
||||
'processing_error' => $error,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user