CleanupFileLocks.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files\BackgroundJob;
  8. use OC\Lock\DBLockingProvider;
  9. use OCP\AppFramework\Utility\ITimeFactory;
  10. use OCP\BackgroundJob\TimedJob;
  11. /**
  12. * Clean up all file locks that are expired for the DB file locking provider
  13. */
  14. class CleanupFileLocks extends TimedJob {
  15. /**
  16. * Default interval in minutes
  17. *
  18. * @var int $defaultIntervalMin
  19. **/
  20. protected $defaultIntervalMin = 5;
  21. /**
  22. * sets the correct interval for this timed job
  23. */
  24. public function __construct(ITimeFactory $time) {
  25. parent::__construct($time);
  26. $this->interval = $this->defaultIntervalMin * 60;
  27. }
  28. /**
  29. * Makes the background job do its work
  30. *
  31. * @param array $argument unused argument
  32. * @throws \Exception
  33. */
  34. public function run($argument) {
  35. $lockingProvider = \OC::$server->getLockingProvider();
  36. if ($lockingProvider instanceof DBLockingProvider) {
  37. $lockingProvider->cleanExpiredLocks();
  38. }
  39. }
  40. }