64 lines
1.3 KiB
PHP
64 lines
1.3 KiB
PHP
<?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;
|
||
|
|
}
|
||
|
|
}
|