-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce new cronjob to regularly cleanup outdated lock files if fil…
…e based lock provider is being used.
- Loading branch information
Showing
4 changed files
with
112 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Copyright 2024 Adobe | ||
* All Rights Reserved. | ||
*/ | ||
namespace Magento\Backend\Cron; | ||
|
||
use Magento\Framework\Lock\Backend\FileLock; | ||
use Magento\Framework\Lock\LockBackendFactory; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class CleanLocks | ||
{ | ||
/** | ||
* @param LockBackendFactory $lockFactory | ||
* @param LoggerInterface $logger | ||
*/ | ||
public function __construct( | ||
private readonly LockBackendFactory $lockFactory, | ||
private readonly LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
/** | ||
* Cron job to cleanup old locks | ||
*/ | ||
public function execute(): void | ||
{ | ||
$locker = $this->lockFactory->create(); | ||
|
||
if ($locker instanceof FileLock) { | ||
$numberOfLockFilesDeleted = $locker->cleanupOldLocks(); | ||
|
||
$this->logger->info(sprintf('Deleted %d old lock files', $numberOfLockFilesDeleted)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters