1
0

ClearOldStatusesBackgroundJob.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\UserStatus\BackgroundJob;
  8. use OCA\UserStatus\Db\UserStatusMapper;
  9. use OCA\UserStatus\Service\StatusService;
  10. use OCP\AppFramework\Utility\ITimeFactory;
  11. use OCP\BackgroundJob\TimedJob;
  12. /**
  13. * Class ClearOldStatusesBackgroundJob
  14. *
  15. * @package OCA\UserStatus\BackgroundJob
  16. */
  17. class ClearOldStatusesBackgroundJob extends TimedJob {
  18. /** @var UserStatusMapper */
  19. private $mapper;
  20. /**
  21. * ClearOldStatusesBackgroundJob constructor.
  22. *
  23. * @param ITimeFactory $time
  24. * @param UserStatusMapper $mapper
  25. */
  26. public function __construct(ITimeFactory $time,
  27. UserStatusMapper $mapper) {
  28. parent::__construct($time);
  29. $this->mapper = $mapper;
  30. // Run every time the cron is run
  31. $this->setInterval(60);
  32. }
  33. /**
  34. * @inheritDoc
  35. */
  36. protected function run($argument) {
  37. $now = $this->time->getTime();
  38. $this->mapper->clearOlderThanClearAt($now);
  39. $this->mapper->clearStatusesOlderThan($now - StatusService::INVALIDATE_STATUS_THRESHOLD, $now);
  40. }
  41. }