feat(pargar): cap inbound mande/document logs after insert
Keep the newest 2000 success rows per inbound type so dumps stop growing from Pargar webhooks, and store compact document payloads instead of full JSON. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\DatabaseLogPruneService;
|
||||
use App\Services\PargarSyncService;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
@@ -46,6 +48,26 @@ class PargarSyncLog extends Model
|
||||
return self::$hasConfirmedAtColumn;
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::created(function (self $log) {
|
||||
if (! in_array($log->type, [PargarSyncService::TYPE_MANDE, PargarSyncService::TYPE_DOCUMENT], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(function () {
|
||||
if (function_exists('fastcgi_finish_request')) {
|
||||
@fastcgi_finish_request();
|
||||
}
|
||||
try {
|
||||
app(DatabaseLogPruneService::class)->prunePargarInboundOverflow();
|
||||
} catch (\Throwable) {
|
||||
// وبهوک پرگار نباید بهخاطر پاکسازی قطع شود
|
||||
}
|
||||
})->afterResponse();
|
||||
});
|
||||
}
|
||||
|
||||
public function customer(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
|
||||
Reference in New Issue
Block a user