PHP code example of codeldev / laravel-job-log

1. Go to this page and download the library: Download codeldev/laravel-job-log library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codeldev / laravel-job-log example snippets


return [
    'prune_days' => (int) env('JOB_LOG_PRUNE_DAYS', 365),
    'model' => CodelDev\LaravelJobLog\Models\LaravelJobLog::class,
    'table' => env('JOB_LOG_TABLE', 'job_log'),
];

Schedule::command('job-log:prune')
    ->weeklyOn(1, '02:30')
    ->withoutOverlapping();

use CodelDev\LaravelJobLog\Models\LaravelJobLog;
use CodelDev\LaravelJobLog\Enums\LaravelJobRunStatusEnum;

// Get all logs
LaravelJobLog::all();

// Filter by status
LaravelJobLog::query()
->where('status', LaravelJobRunStatusEnum::SUCCEEDED)
->get();

LaravelJobLog::query()
->where('status', LaravelJobRunStatusEnum::FAILED)
->get();

LaravelJobLog::query()
->where('status', LaravelJobRunStatusEnum::RUNNING)
->get();

// Filter by job class
LaravelJobLog::query()
    ->where('job', 'App\\Jobs\\MyJob')
    ->get();

// Filter by queue
LaravelJobLog::query()
    ->where('queue', 'default')
    ->get();

// Jobs from the last 24 hours
LaravelJobLog::query()
    ->where('started_at', '>=', now()->subDay())
    ->get();

// Slow jobs (over 1 second)
LaravelJobLog::query()
    ->where('duration_ms', '>', 1000)
    ->orderBy('duration_ms', 'desc')
    ->get();

// Failed jobs with exception details
LaravelJobLog::query()
    ->where('status', LaravelJobRunStatusEnum::FAILED)
    ->with('failedJob')
    ->get();

// Paginate results
LaravelJobLog::query()
    ->orderBy('created_at', 'desc')
    ->paginate(15);

use CodelDev\LaravelJobLog\Models\LaravelJobLog as BaseJobLog;

class JobLog extends BaseJobLog
{
    public function scopeFailed($query)
    {
        return $query->where('status', LaravelJobRunStatusEnum::FAILED);
    }
}

'model' => \App\Models\JobLog::class,
bash
php artisan vendor:publish --tag="job-log-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="job-log-config"
dotenv
JOB_LOG_PRUNE_DAYS=365
JOB_LOG_TABLE=job_log
bash
php artisan job-log:prune