mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-18 13:12:16 +01:00
Added failed jobs to admin panel
This commit is contained in:
committed by
Constantin Graf
parent
055d93f7a3
commit
855db81104
112
app/Filament/Resources/FailedJobsResource.php
Normal file
112
app/Filament/Resources/FailedJobsResource.php
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
|
use App\Filament\Resources\FailedJobsResource\ListFailedJobs;
|
||||||
|
use App\Models\FailedJob;
|
||||||
|
use Filament\Forms\Components\Textarea;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Tables\Actions\Action;
|
||||||
|
use Filament\Tables\Actions\BulkAction;
|
||||||
|
use Filament\Tables\Actions\DeleteAction;
|
||||||
|
use Filament\Tables\Actions\ViewAction;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
use Novadaemon\FilamentPrettyJson\PrettyJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @source https://gitlab.com/amvisor/filament-failed-jobs
|
||||||
|
*/
|
||||||
|
class FailedJobsResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = FailedJob::class;
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'heroicon-o-exclamation-circle';
|
||||||
|
|
||||||
|
protected static ?string $navigationGroup = 'System';
|
||||||
|
|
||||||
|
public static function getNavigationBadge(): ?string
|
||||||
|
{
|
||||||
|
return (string) FailedJob::query()->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function form(Form $form): Form
|
||||||
|
{
|
||||||
|
return $form
|
||||||
|
->schema([
|
||||||
|
TextInput::make('uuid')->disabled()->columnSpan(4),
|
||||||
|
TextInput::make('failed_at')->disabled(),
|
||||||
|
TextInput::make('id')->disabled(),
|
||||||
|
TextInput::make('connection')->disabled(),
|
||||||
|
TextInput::make('queue')->disabled(),
|
||||||
|
|
||||||
|
// make text a little bit smaller because often a complete Stack Trace is shown:
|
||||||
|
TextArea::make('exception')->disabled()->columnSpan(4)->extraInputAttributes(['style' => 'font-size: 80%;']),
|
||||||
|
PrettyJson::make('payload')->disabled()->columnSpan(4),
|
||||||
|
])->columns(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->defaultSort('id', 'desc')
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('id')->sortable()->searchable()->toggleable(),
|
||||||
|
TextColumn::make('failed_at')->sortable()->searchable(false)->toggleable(),
|
||||||
|
TextColumn::make('exception')
|
||||||
|
->sortable()
|
||||||
|
->searchable()
|
||||||
|
->toggleable()
|
||||||
|
->wrap()
|
||||||
|
->limit(200)
|
||||||
|
->tooltip(fn (FailedJob $record) => "{$record->failed_at} UUID: {$record->uuid}; Connection: {$record->connection}; Queue: {$record->queue};"),
|
||||||
|
TextColumn::make('uuid')->sortable()->searchable()->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
TextColumn::make('connection')->sortable()->searchable()->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
TextColumn::make('queue')->sortable()->searchable()->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
])
|
||||||
|
->filters([])
|
||||||
|
->bulkActions([
|
||||||
|
BulkAction::make('retry')
|
||||||
|
->label('Retry')
|
||||||
|
->requiresConfirmation()
|
||||||
|
->action(function (Collection $records): void {
|
||||||
|
/** @var FailedJob $record */
|
||||||
|
foreach ($records as $record) {
|
||||||
|
Artisan::call("queue:retry {$record->uuid}");
|
||||||
|
}
|
||||||
|
Notification::make()
|
||||||
|
->title("{$records->count()} jobs have been pushed back onto the queue.")
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
->actions([
|
||||||
|
DeleteAction::make('Delete'),
|
||||||
|
ViewAction::make('View'),
|
||||||
|
Action::make('retry')
|
||||||
|
->label('Retry')
|
||||||
|
->requiresConfirmation()
|
||||||
|
->action(function (FailedJob $record): void {
|
||||||
|
Artisan::call("queue:retry {$record->uuid}");
|
||||||
|
Notification::make()
|
||||||
|
->title("The job with uuid '{$record->uuid}' has been pushed back onto the queue.")
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ListFailedJobs::route('/'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
45
app/Filament/Resources/FailedJobsResource/ListFailedJobs.php
Normal file
45
app/Filament/Resources/FailedJobsResource/ListFailedJobs.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\FailedJobsResource;
|
||||||
|
|
||||||
|
use App\Filament\Resources\FailedJobsResource;
|
||||||
|
use App\Models\FailedJob;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Pages\Actions\Action;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
|
||||||
|
class ListFailedJobs extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = FailedJobsResource::class;
|
||||||
|
|
||||||
|
public function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Action::make('retry_all')
|
||||||
|
->label('Retry all failed Jobs')
|
||||||
|
->requiresConfirmation()
|
||||||
|
->action(function (): void {
|
||||||
|
Artisan::call('queue:retry all');
|
||||||
|
Notification::make()
|
||||||
|
->title('All failed jobs have been pushed back onto the queue.')
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
}),
|
||||||
|
|
||||||
|
Action::make('delete_all')
|
||||||
|
->label('Delete all failed Jobs')
|
||||||
|
->requiresConfirmation()
|
||||||
|
->color('danger')
|
||||||
|
->action(function (): void {
|
||||||
|
FailedJob::truncate();
|
||||||
|
Notification::make()
|
||||||
|
->title('All failed jobs have been removed.')
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Models/FailedJob.php
Normal file
34
app/Models/FailedJob.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property string $uuid
|
||||||
|
* @property string $connection
|
||||||
|
* @property string $queue
|
||||||
|
* @property Carbon $failed_at
|
||||||
|
*/
|
||||||
|
class FailedJob extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be cast to native types.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
protected $casts = [
|
||||||
|
'failed_at' => 'datetime',
|
||||||
|
'payload' => 'json',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
"laravel/passport": "^12.0",
|
"laravel/passport": "^12.0",
|
||||||
"laravel/tinker": "^2.8",
|
"laravel/tinker": "^2.8",
|
||||||
"league/flysystem-aws-s3-v3": "^3.0",
|
"league/flysystem-aws-s3-v3": "^3.0",
|
||||||
|
"novadaemon/filament-pretty-json": "^2.2",
|
||||||
"nwidart/laravel-modules": "^11.0.11",
|
"nwidart/laravel-modules": "^11.0.11",
|
||||||
"pxlrbt/filament-environment-indicator": "^2.0",
|
"pxlrbt/filament-environment-indicator": "^2.0",
|
||||||
"spatie/temporary-directory": "^2.2",
|
"spatie/temporary-directory": "^2.2",
|
||||||
|
|||||||
68
composer.lock
generated
68
composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "cd6f3efa43ee6a6576c68bdb0b69a19e",
|
"content-hash": "398572ca3d095ca043c84e7dfb4f051a",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "anourvalar/eloquent-serialize",
|
"name": "anourvalar/eloquent-serialize",
|
||||||
@@ -6287,6 +6287,72 @@
|
|||||||
},
|
},
|
||||||
"time": "2024-03-05T20:51:40+00:00"
|
"time": "2024-03-05T20:51:40+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "novadaemon/filament-pretty-json",
|
||||||
|
"version": "v2.2.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/novadaemon/filament-pretty-json.git",
|
||||||
|
"reference": "b295957f240cf848ffd402d842e9db6e7b5346f3"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/novadaemon/filament-pretty-json/zipball/b295957f240cf848ffd402d842e9db6e7b5346f3",
|
||||||
|
"reference": "b295957f240cf848ffd402d842e9db6e7b5346f3",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"filament/filament": "^3.0",
|
||||||
|
"filament/forms": "^3.0",
|
||||||
|
"illuminate/contracts": "^10.0|^11.0",
|
||||||
|
"php": "^8.1|^8.2",
|
||||||
|
"spatie/laravel-package-tools": "^1.15.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"laravel/pint": "^1.0",
|
||||||
|
"nunomaduro/collision": "^7.9|^8.1",
|
||||||
|
"phpstan/extension-installer": "^1.1"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"laravel": {
|
||||||
|
"providers": [
|
||||||
|
"Novadaemon\\FilamentPrettyJson\\FilamentPrettyJsonServiceProvider"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Novadaemon\\FilamentPrettyJson\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Jesús García",
|
||||||
|
"email": "novadaemon@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Read-only field to show pretty json in your filamentphp forms",
|
||||||
|
"homepage": "https://github.com/novadaemon/filament-pretty-json",
|
||||||
|
"keywords": [
|
||||||
|
"Forms",
|
||||||
|
"field",
|
||||||
|
"filament",
|
||||||
|
"filament-pretty-json",
|
||||||
|
"json",
|
||||||
|
"laravel",
|
||||||
|
"novadaemon"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/novadaemon/filament-pretty-json/issues",
|
||||||
|
"source": "https://github.com/novadaemon/filament-pretty-json"
|
||||||
|
},
|
||||||
|
"time": "2024-06-08T20:19:44+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "nunomaduro/termwind",
|
"name": "nunomaduro/termwind",
|
||||||
"version": "v2.0.1",
|
"version": "v2.0.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user