From 0958806b2224ec923f191e17925f1e18b7c73b09 Mon Sep 17 00:00:00 2001 From: Mediacamp Date: Thu, 5 Aug 2021 21:45:57 +0200 Subject: [PATCH] JWK-76 unlock lock files --- Cron/CheckLockFiles.php | 86 +++++++++++++++++++++++++++++++++++++++++ etc/crontab.xml | 3 ++ 2 files changed, 89 insertions(+) create mode 100644 Cron/CheckLockFiles.php diff --git a/Cron/CheckLockFiles.php b/Cron/CheckLockFiles.php new file mode 100644 index 0000000..fc63cdd --- /dev/null +++ b/Cron/CheckLockFiles.php @@ -0,0 +1,86 @@ + + * @copyright 2021 Walkthechat + * + * @license See LICENSE.txt for license details. + */ + +namespace Walkthechat\Walkthechat\Cron; + +/** + * Class CheckLockFiles + * + * @package Walkthechat\Walkthechat\Cron + */ +class CheckLockFiles +{ + /** + * @var \Magento\Framework\Filesystem + */ + protected $filesystem; + + /** + * @var integer + */ + const LOCK_FILE_MINUTES = 30; + + /** + * CheckLockFiles constructor. + * @param \Magento\Framework\Filesystem $filesystem + */ + public function __construct( + \Magento\Framework\Filesystem $filesystem + ) + { + $this->filesystem = $filesystem; + } + + /** + * + * @throws \Magento\Framework\Exception\CronException + * @throws \Exception + */ + public function execute() + { + $directory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR); + + if ($directory->isExist(\Walkthechat\Walkthechat\Cron\ProcessQueue::QUEUE_LOCK_FILE_NAME_LOCKED)) { + $stat = $directory->stat(\Walkthechat\Walkthechat\Cron\ProcessQueue::QUEUE_LOCK_FILE_NAME_LOCKED); + + if (isset($stat['ctime']) && $stat['ctime'] < (time() - self::LOCK_FILE_MINUTES * 60)) { + try { + $directory->renameFile(\Walkthechat\Walkthechat\Cron\ProcessQueue::QUEUE_LOCK_FILE_NAME_LOCKED, \Walkthechat\Walkthechat\Cron\ProcessQueue::QUEUE_LOCK_FILE_NAME_UNLOCKED); + } catch (\Magento\Framework\Exception\FileSystemException $e) { + throw new \Magento\Framework\Exception\CronException(__('Unable to unlock the walkthechat queue.')); + } + } + } + + if ($directory->isExist(\Walkthechat\Walkthechat\Cron\SyncImages::SYNC_IMAGES_LOCK_FILE_NAME_LOCKED)) { + $stat = $directory->stat(\Walkthechat\Walkthechat\Cron\SyncImages::SYNC_IMAGES_LOCK_FILE_NAME_LOCKED); + + if (isset($stat['ctime']) && $stat['ctime'] < (time() - self::LOCK_FILE_MINUTES * 60)) { + try { + $directory->renameFile(\Walkthechat\Walkthechat\Cron\SyncImages::SYNC_IMAGES_LOCK_FILE_NAME_LOCKED, \Walkthechat\Walkthechat\Cron\SyncImages::SYNC_IMAGES_LOCK_FILE_NAME_UNLOCKED); + } catch (\Magento\Framework\Exception\FileSystemException $e) { + throw new \Magento\Framework\Exception\CronException(__('Unable to unlock the walkthechat sync images.')); + } + } + } + + if ($directory->isExist(\Walkthechat\Walkthechat\Cron\SyncInventory::LOCK_FILE_NAME_LOCKED)) { + $stat = $directory->stat(\Walkthechat\Walkthechat\Cron\SyncInventory::LOCK_FILE_NAME_LOCKED); + + if (isset($stat['ctime']) && $stat['ctime'] < (time() - self::LOCK_FILE_MINUTES * 60)) { + try { + $directory->renameFile(\Walkthechat\Walkthechat\Cron\SyncInventory::LOCK_FILE_NAME_LOCKED, \Walkthechat\Walkthechat\Cron\SyncInventory::LOCK_FILE_NAME_UNLOCKED); + } catch (\Magento\Framework\Exception\FileSystemException $e) { + throw new \Magento\Framework\Exception\CronException(__('Unable to unlock the walkthechat inventory.')); + } + } + } + } +} diff --git a/etc/crontab.xml b/etc/crontab.xml index 7f9e333..df1ba54 100755 --- a/etc/crontab.xml +++ b/etc/crontab.xml @@ -13,5 +13,8 @@ 0 * * * * + + */5 * * * * +