Skip to content

Commit

Permalink
Add config values for lock timeout and lock wait
Browse files Browse the repository at this point in the history
  • Loading branch information
jared-cannon committed Jan 21, 2025
1 parent 0acc2ff commit 7efd3be
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
12 changes: 12 additions & 0 deletions config/rewind.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,16 @@
*/

'listener_should_queue' => env('LARAVEL_REWIND_LISTENER_SHOULD_QUEUE', false),

/*
|--------------------------------------------------------------------------
| Concurrency Settings
|--------------------------------------------------------------------------
|
| Define how long to wait (in seconds) for lock acquisition before timing out,
| and how long the lock should remain valid if the process unexpectedly ends.
*/

'lock_wait' => env('REWIND_LOCK_WAIT', 10),
'lock_timeout' => env('REWIND_LOCK_TIMEOUT', 10),
];
8 changes: 8 additions & 0 deletions src/Exceptions/CurrentVersionColumnMissingException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace AvocetShores\LaravelRewind\Exceptions;

class CurrentVersionColumnMissingException
{

}
4 changes: 2 additions & 2 deletions src/Listeners/CreateRewindVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public function handle(RewindVersionCreating $event): void

$lock = cache()->lock(
sprintf('laravel-rewind-version-lock-%s-%s', $model->getTable(), $model->getKey()),
10
config('rewind.lock_timeout', 10)
);

try {
$lock->block(10);
$lock->block(config('rewind.lock_wait', 10));

// Re-check that something is dirty (edge case: might be no changes after all)
$dirty = $model->getDirty();
Expand Down

0 comments on commit 7efd3be

Please sign in to comment.