PHP code example of spatie / laravel-queued-db-cleanup
1. Go to this page and download the library: Download spatie/laravel-queued-db-cleanup 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/ */
spatie / laravel-queued-db-cleanup example snippets
return [
/*
* To make sure there's only one job of a particular cleanup running,
* this package uses a lock. Here, you can configure the default
* store to be used by the lock and the release time.
*/
'lock' => [
'cache_store' => 'redis',
'release_lock_after_seconds' => 60 * 20
],
/*
* The class name of the job that will clean that database.
*
* This should be `Spatie\LaravelQueuedDbCleanup\Jobs\CleanDatabaseJob`
* or a class that extends it.
*/
'clean_database_job_class' => Spatie\LaravelQueuedDbCleanup\Jobs\CleanDatabaseJob::class,
/*
* In order to handle deadlocks on a high traffic table, the package can
* automatically retry the transaction that performs the delete query
* a specified number of times
*/
'delete_query_attempts' => 3,
];
$batch = CleanDatabaseJobFactory::forQuery(YourModel::query())
->deleteChunkSize(10)
->getBatch();
// you could store this batch id somewhere
$batchId = $batch->id;
$batch->dispatch();