Skip to content

Commit c99d53a

Browse files
committed
feat: add delivery attempts tracking with view page section
- WebhookDeliveryAttempt model with migration (uuid PK, cascading FK) - Replay actions now create delivery attempt records (pending → completed/failed) - View page shows collapsible "Delivery Attempts" section with RepeatableEntry showing action, status, error, and timestamp
1 parent 1899f4e commit c99d53a

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('webhook_delivery_attempts', function (Blueprint $table) {
12+
$table->uuid('id')->primary();
13+
$table->uuid('inbound_webhook_id');
14+
$table->string('action');
15+
$table->string('status')->default('pending');
16+
$table->text('error_message')->nullable();
17+
$table->timestamps();
18+
19+
$table->foreign('inbound_webhook_id')
20+
->references('id')
21+
->on('inbound_webhooks')
22+
->cascadeOnDelete();
23+
24+
$table->index('inbound_webhook_id');
25+
});
26+
}
27+
28+
public function down(): void
29+
{
30+
Schema::dropIfExists('webhook_delivery_attempts');
31+
}
32+
};

src/Filament/Admin/Resources/InboundWebhook/Pages/ListInboundWebhooks.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,26 @@ public function table(Table $table): Table
8787
'error_message' => null,
8888
]);
8989

90+
$attempt = $record->deliveryAttempts()->create([
91+
'action' => 'replay',
92+
'status' => 'pending',
93+
]);
94+
9095
try {
9196
InboundWebhookReceived::dispatch($record);
9297

9398
$record->update([
9499
'status' => InboundWebhookStatus::Completed,
95100
'processed_at' => now(),
96101
]);
102+
$attempt->update(['status' => 'completed']);
97103
} catch (\Throwable $e) {
98104
$record->update([
99105
'status' => InboundWebhookStatus::Failed,
100106
'processed_at' => now(),
101107
'error_message' => $e->getMessage(),
102108
]);
109+
$attempt->update(['status' => 'failed', 'error_message' => $e->getMessage()]);
103110

104111
throw $e;
105112
}

src/Filament/Admin/Resources/InboundWebhook/Pages/ViewInboundWebhook.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
use Basement\Webhooks\Models\InboundWebhook;
1111
use Filament\Actions\Action;
1212
use Filament\Infolists\Components\CodeEntry;
13+
use Filament\Infolists\Components\RepeatableEntry;
1314
use Filament\Infolists\Components\TextEntry;
1415
use Filament\Resources\Pages\ViewRecord;
1516
use Filament\Schemas\Components\Grid;
17+
use Filament\Schemas\Components\Section;
1618
use Filament\Schemas\Schema;
1719
use Filament\Support\Icons\Heroicon;
1820
use Phiki\Grammar\Grammar;
@@ -55,6 +57,27 @@ public function infolist(Schema $schema): Schema
5557
->copyable()
5658
->copyMessage('Payload copied to clipboard')
5759
->columnSpanFull(),
60+
Section::make('Delivery Attempts')
61+
->collapsible()
62+
->columnSpanFull()
63+
->visible(fn ($record) => $record->deliveryAttempts()->exists())
64+
->schema([
65+
RepeatableEntry::make('deliveryAttempts')
66+
->hiddenLabel()
67+
->columnSpanFull()
68+
->schema([
69+
TextEntry::make('action')
70+
->badge(),
71+
TextEntry::make('status')
72+
->badge(),
73+
TextEntry::make('error_message')
74+
->color('danger')
75+
->visible(fn ($state) => $state !== null),
76+
TextEntry::make('created_at')
77+
->dateTime()
78+
->label('Attempted At'),
79+
]),
80+
]),
5881
]);
5982
}
6083

@@ -77,19 +100,26 @@ protected function getHeaderActions(): array
77100
'error_message' => null,
78101
]);
79102

103+
$attempt = $record->deliveryAttempts()->create([
104+
'action' => 'replay',
105+
'status' => 'pending',
106+
]);
107+
80108
try {
81109
InboundWebhookReceived::dispatch($record);
82110

83111
$record->update([
84112
'status' => InboundWebhookStatus::Completed,
85113
'processed_at' => now(),
86114
]);
115+
$attempt->update(['status' => 'completed']);
87116
} catch (\Throwable $e) {
88117
$record->update([
89118
'status' => InboundWebhookStatus::Failed,
90119
'processed_at' => now(),
91120
'error_message' => $e->getMessage(),
92121
]);
122+
$attempt->update(['status' => 'failed', 'error_message' => $e->getMessage()]);
93123

94124
throw $e;
95125
}

0 commit comments

Comments
 (0)