Skip to content

Commit

Permalink
Structures::mutexTimeout (#3148)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Aug 4, 2018
1 parent 8a1a855 commit 6f710e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Added
- Added the `craft.query()` template function, for creating new database queries.
- Added `craft\services\Structures::mutexTimeout`. ([#3148](https://github.com/craftcms/cms/issues/3148))

### Fixed
- Craft’s console commands now return the correct exit codes. ([#3175](https://github.com/craftcms/cms/issues/3175))
Expand Down
7 changes: 6 additions & 1 deletion src/services/Structures.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class Structures extends Component
// Properties
// =========================================================================

/**
* @var int The timeout to pass to [[\yii\mutex\Mutex::acquire()]] when acquiring a lock on the structure.
*/
public $mutexTimeout = 0;

/**
* @var
*/
Expand Down Expand Up @@ -348,7 +353,7 @@ private function _doIt($structureId, ElementInterface $element, StructureElement
// Get a lock or bust
$lockName = 'structure:' . $structureId;
$mutex = Craft::$app->getMutex();
if (!$mutex->acquire($lockName)) {
if (!$mutex->acquire($lockName, $this->mutexTimeout)) {
throw new Exception('Unable to acquire a lock for the structure ' . $structureId);
}

Expand Down

0 comments on commit 6f710e8

Please sign in to comment.