This commit is contained in:
Doar Mihai
2026-04-03 20:41:35 +03:00
parent 19d5e23dfd
commit a8a48f3f6f
13 changed files with 1185 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class JobFetchLog extends Model
{
protected $fillable = [
'job_source_id',
'success',
'jobs_fetched',
'jobs_created',
'jobs_updated',
'jobs_skipped',
'duration_seconds',
'error_message',
'metadata',
];
protected $casts = [
'success' => 'boolean',
'metadata' => 'array',
];
public function source(): BelongsTo
{
return $this->belongsTo(JobSource::class, 'job_source_id');
}
/**
* Scope to get only successful logs
*/
public function scopeSuccessful($query)
{
return $query->where('success', true);
}
/**
* Scope to get only failed logs
*/
public function scopeFailed($query)
{
return $query->where('success', false);
}
/**
* Scope to get logs within a date range
*/
public function scopeWithinDays($query, int $days)
{
return $query->where('created_at', '>=', now()->subDays($days));
}
/**
* Get total jobs processed
*/
public function getTotalJobsProcessedAttribute(): int
{
return $this->jobs_created + $this->jobs_updated + $this->jobs_skipped;
}
}