SyncJob.php 919 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Federation;
  8. use OCP\AppFramework\Utility\ITimeFactory;
  9. use OCP\BackgroundJob\TimedJob;
  10. use Psr\Log\LoggerInterface;
  11. class SyncJob extends TimedJob {
  12. public function __construct(
  13. protected SyncFederationAddressBooks $syncService,
  14. protected LoggerInterface $logger,
  15. ITimeFactory $timeFactory,
  16. ) {
  17. parent::__construct($timeFactory);
  18. // Run once a day
  19. $this->setInterval(24 * 60 * 60);
  20. $this->setTimeSensitivity(self::TIME_INSENSITIVE);
  21. }
  22. protected function run($argument) {
  23. $this->syncService->syncThemAll(function ($url, $ex): void {
  24. if ($ex instanceof \Exception) {
  25. $this->logger->error("Error while syncing $url.", [
  26. 'app' => 'fed-sync',
  27. 'exception' => $ex,
  28. ]);
  29. }
  30. });
  31. }
  32. }