PHP code example of ahed92wakim / laravel-db-transaction-retry
1. Go to this page and download the library: Download ahed92wakim/laravel-db-transaction-retry library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ahed92wakim / laravel-db-transaction-retry example snippets
use DatabaseTransactions\RetryHelper\Services\TransactionRetrier as Retry;
$order = Retry::runWithRetry(
function () use ($payload) {
$order = Order::create($payload);
$order->logAuditTrail();
return $order;
},
maxRetries: 4,
retryDelay: 1,
trxLabel: 'order-create'
);
$invoice = DB::transactionWithRetry(
function () use ($payload) {
return Invoice::fromPayload($payload);
},
maxRetries: 5,
retryDelay: 1,
trxLabel: 'invoice-sync'
);
$report = DB::connection('analytics')->transactionWithRetry(
fn () => $builder->lockForUpdate()->selectRaw('count(*) as total')->first(),
trxLabel: 'analytics-rollup'
);
use DatabaseTransactions\RetryHelper\TransactionRetryDashboard;
use Illuminate\Support\Facades\Gate;
Gate::define('viewTransactionRetryDashboard', function ($user) {
return in_array($user->email, [
// ...
], true);
});
TransactionRetryDashboard::auth(function ($request) {
return app()->environment('local')
|| Gate::check('viewTransactionRetryDashboard', [$request->user()]);
});
return [
App\Providers\TransactionRetryDashboardServiceProvider::class,
];
'dashboard' => [
'middleware' => ['web', 'auth', 'can:viewTransactionRetryDashboard'],
],
'api' => [
'middleware' => ['web', 'auth', 'can:viewTransactionRetryDashboard'],
],
use Illuminate\Support\Facades\Schedule;
Schedule::command('db-transaction-retry:roll-partitions --hours=24 --table=transaction_retry_events')->hourly();
Schedule::command('db-transaction-retry:roll-partitions --hours=24 --table=db_transaction_logs')->hourly();
Schedule::command('db-transaction-retry:roll-partitions --hours=24 --table=db_request_logs')->hourly();
Schedule::command('db-transaction-retry:roll-partitions --hours=24 --table=db_exceptions')->hourly();
bash
php artisan db-transaction-retry:install
php artisan migrate
bash
php artisan vendor:publish --tag=database-transaction-retry-config
bash
php artisan db-transaction-retry:install
php artisan migrate
bash
php artisan vendor:publish --tag=database-transaction-retry-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=database-transaction-retry-dashboard
bash
php artisan db-transaction-retry:stop # disable retries
php artisan db-transaction-retry:start # enable retries