Skip to content

Commit

Permalink
Merge pull request #117 from cego/rab/skip-locked-configurable
Browse files Browse the repository at this point in the history
Added config to opt out of using skip locked for older versions of mysql
  • Loading branch information
RasmusBorup authored Dec 30, 2024
2 parents 9a9d05d + 3b14de3 commit f894364
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 7 additions & 1 deletion publishable/config/request-insurance.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,11 @@
'table_edits' => null,
'table_edit_approvals' => null,

'useDbReconnect' => env('REQUEST_INSURANCE_WORKER_USE_DB_RECONNECT', true)
'useDbReconnect' => env('REQUEST_INSURANCE_WORKER_USE_DB_RECONNECT', true),

/*
| Using skip locked optimizes request insurance to run with multiple worker threads,
| but is unavailable in mysql versions older than 8.0.0
*/
'useSkipLocked' => env('REQUEST_INSURANCE_WORKER_USE_SKIP_LOCKED', true),
];
14 changes: 10 additions & 4 deletions src/RequestInsurance/RequestInsuranceWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,17 @@ public function acquireLockOnRowsToProcess(): Collection
*/
public function getIdsOfReadyRequests()
{
return resolve(RequestInsurance::class)::query()
$builder = resolve(RequestInsurance::class)::query()
->select('id')
->readyToBeProcessed()
->take(Config::get('request-insurance.batchSize'))
->lock('FOR UPDATE SKIP LOCKED')
->pluck('id');
->take(Config::get('request-insurance.batchSize'));

if (config('request-insurance.useSkipLockede')) {
$builder->lock('FOR UPDATE SKIP LOCKED');
} else {
$builder->lockForUpdate();
}

return $builder->pluck('id');
}
}

0 comments on commit f894364

Please sign in to comment.