diff --git a/.github/workflows/main-tests.yml b/.github/workflows/main-tests.yml new file mode 100644 index 0000000..c13aa12 --- /dev/null +++ b/.github/workflows/main-tests.yml @@ -0,0 +1,74 @@ +name: tests + +on: + push: + branches: + - main + pull_request: + schedule: + - cron: '0 0 * * *' + +jobs: + tests: + runs-on: ubuntu-22.04 + + services: + redis: + image: redis + ports: + - 6379:6379 + options: --entrypoint redis-server + + strategy: + fail-fast: true + matrix: + php: [7.3, 7.4, '8.0', 8.1, 8.2, 8.3] + laravel: [8, 9, 10, 11] + exclude: + - php: 7.3 + laravel: 9 + - php: 7.3 + laravel: 10 + - php: 7.3 + laravel: 11 + - php: 7.4 + laravel: 9 + - php: 7.4 + laravel: 10 + - php: 7.4 + laravel: 11 + - php: '8.0' + laravel: 10 + - php: '8.0' + laravel: 11 + - php: 8.1 + laravel: 11 + - php: 8.2 + laravel: 8 + - php: 8.3 + laravel: 8 + - php: 8.3 + laravel: 9 + + name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, redis, zip + ini-values: error_reporting=E_ALL + tools: composer:v2 + coverage: none + + - name: Install dependencies + run: | + composer require "illuminate/contracts=^${{ matrix.laravel }}" --dev --no-update + composer update --prefer-dist --no-interaction --no-progress + + - name: Execute tests + run: vendor/bin/phpunit diff --git a/README.md b/README.md index 32931a4..4ddd004 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,19 @@
# Laravel Failed Jobs -If you're running an application and the queue driver isn't Redis, which Laravel Horizon supports, you might be missing out on the elegant features it offers. Laravel Horizon is known for its elegance and a wide range of implemented features. One of its standout features is its ability to present detailed information about failed job payloads and automatically load new failed jobs. +## Introduction: + +If you're running an application with a queue driver other than Redis, which is exclusively supported by [Laravel Horizon](https://github.com/laravel/horizon), you might be missing out on the elegant features that Horizon offers. Laravel Horizon is known for its elegance and a wide range of implemented features. One of its standout features is its ability to present detailed information about failed job payloads and automatically load new failed jobs. In your specific application, if you've been longing for a similar Horizon-like UI to monitor failed_jobs, the Laravel-Failed-Jobs package has got you covered. This package simplifies the process of visualizing failed jobs. +![Screenshot 2024-02-01 at 7 55 42 PM](https://github.com/HPWebdeveloper/laravel-failed-jobs/assets/16323354/2ec7ebad-1ad9-4927-8bff-5ce4002e1a7c) + ## Key Benefits: Seamless Integration: You can seamlessly integrate the Laravel-Failed-Jobs package into your project, even if you are already using Laravel Horizon. There's no conflict between the two. While Horizon primarily reads and writes data to Redis, Laravel-Failed-Jobs retrieves data from the failed_jobs table. @@ -32,12 +35,17 @@ After installing Laravel-Failed-Jobs, publish its assets using the failedjobs:in ```bash php artisan failedjobs:install ``` +## Dashboard + +The Laravel-Failed-Jobs dashboard may be accessed via the `/failedjobs` route. ## Dashboard Authorization -Find `app/Providers/FailedJobsServiceProvider.php` and then follow the same tutorial here: +Find `app/Providers/FailedJobsServiceProvider.php` and then follow the [same document of Horizon](https://laravel.com/docs/10.x/horizon#dashboard-authorization) to secure the dashboard in production environment. + +![Screenshot 2024-02-01 at 7 54 17 PM](https://github.com/HPWebdeveloper/laravel-failed-jobs/assets/16323354/05abc4ab-ede6-4e90-b713-bc540015435d) -https://laravel.com/docs/10.x/horizon#dashboard-authorization +![Screenshot 2024-02-01 at 7 55 27 PM](https://github.com/HPWebdeveloper/laravel-failed-jobs/assets/16323354/30e1dd9e-316b-4d8e-80a4-ef7df195bbcd) ## Licensing diff --git a/composer.json b/composer.json index ac69423..4f8efa5 100644 --- a/composer.json +++ b/composer.json @@ -62,14 +62,6 @@ "minimum-stability": "dev", "prefer-stable": true, "scripts": { - "post-autoload-dump": "@prepare", - "clear": "@php vendor/bin/testbench package:purge-skeleton --ansi", - "prepare": "@php vendor/bin/testbench package:discover --ansi", - "build": "@php vendor/bin/testbench workbench:build --ansi", - "serve": [ - "@build", - "@php vendor/bin/testbench serve" - ], "lint": [ "@php vendor/bin/phpstan analyse" ], diff --git a/src/Http/Controllers/FailedJobsController.php b/src/Http/Controllers/FailedJobsController.php index d4b1a36..c664ba2 100644 --- a/src/Http/Controllers/FailedJobsController.php +++ b/src/Http/Controllers/FailedJobsController.php @@ -11,7 +11,7 @@ class FailedJobsController extends Controller public function index(Request $request) { - $perPage = 50; + $perPage = 50; $failedJobs = DB::table('failed_jobs') ->orderBy('failed_at', 'desc') @@ -40,40 +40,6 @@ protected function decodeDatabaseFailedJob($job) return $job; } - - /** - * Paginate the failed jobs for the request. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Support\Collection - */ - protected function paginate(Request $request) - { - return $this->jobs->getFailed($request->query('starting_at') ?: -1)->map(function ($job) { - return $this->decode($job); - }); - } - - /** - * Paginate the failed jobs for the request and tag. - * - * @param \Illuminate\Http\Request $request - * @param string $tag - * @return \Illuminate\Support\Collection - */ - protected function paginateByTag(Request $request, $tag) - { - $jobIds = $this->tags->paginate( - 'failed:'.$tag, ($request->query('starting_at') ?: -1) + 1, 50 - ); - - $startingAt = $request->query('starting_at', 0); - - return $this->jobs->getJobs($jobIds, $startingAt)->map(function ($job) { - return $this->decode($job); - }); - } - public function show($uuid) { $failedJob = DB::table('failed_jobs')->where('uuid', $uuid)->first(); @@ -98,24 +64,4 @@ protected function decodeDatabaseJob($job) return $job; } - - /** - * Decode the given job. - * - * @param object $job - * @return object - */ - protected function decode($job) - { - $job->payload = json_decode($job->payload); - - $job->exception = mb_convert_encoding($job->exception, 'UTF-8'); - - $job->context = json_decode($job->context); - - $job->retried_by = collect(json_decode($job->retried_by)) - ->sortByDesc('retried_at')->values(); - - return $job; - } }