Skip to content

Commit

Permalink
Add prunable method to QueueMonitor model and
Browse files Browse the repository at this point in the history
filters to QueueMonitorResource table
  • Loading branch information
Baptiste committed Dec 7, 2023
1 parent 08d724f commit 4616bb4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Models/QueueMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Prunable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Hash;

class QueueMonitor extends Model
Expand Down Expand Up @@ -102,7 +103,7 @@ public function hasSucceeded(): bool
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function prunable()
public function prunable(): Builder|bool
{
if (FilamentJobsMonitorPlugin::get()->getPruning()) {
return static::where('created_at', '<=', now()->subDays(FilamentJobsMonitorPlugin::get()->getPruningRetention()));
Expand Down
28 changes: 27 additions & 1 deletion src/Resources/QueueMonitorResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
use Filament\Resources\Resource;
use Filament\Tables\Actions\DeleteBulkAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Builder;


class QueueMonitorResource extends Resource
{
Expand Down Expand Up @@ -49,7 +52,6 @@ public static function table(Table $table): Table
TextColumn::make('status')
->badge()
->label(__('filament-jobs-monitor::translations.status'))
->sortable()
->formatStateUsing(fn (string $state): string => __("filament-jobs-monitor::translations.{$state}"))
->color(fn (string $state): string => match ($state) {
'running' => 'primary',
Expand All @@ -74,6 +76,30 @@ public static function table(Table $table): Table
->defaultSort('started_at', 'desc')
->bulkActions([
DeleteBulkAction::make(),
])
->filters([
SelectFilter::make('status')
->options([
'running' => 'Running',
'succeeded' => 'Succeeded',
'failed' => 'Failed',
])
->query(function (Builder $query, array $data) {
if ($data['value'] === 'succeeded') {
return $query
->whereNotNull('finished_at')
->where('failed', 0);
}
else if ($data['value'] === 'failed') {
return $query
->whereNotNull('finished_at')
->where('failed', 1);
}
else if ($data['value'] === 'running') {
return $query
->whereNull('finished_at');
}
}),
]);
}

Expand Down

0 comments on commit 4616bb4

Please sign in to comment.