You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SyncJob.php 983B

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. protected SyncFederationAddressBooks $syncService;
  13. protected LoggerInterface $logger;
  14. public function __construct(SyncFederationAddressBooks $syncService, LoggerInterface $logger, ITimeFactory $timeFactory) {
  15. parent::__construct($timeFactory);
  16. // Run once a day
  17. $this->setInterval(24 * 60 * 60);
  18. $this->syncService = $syncService;
  19. $this->logger = $logger;
  20. }
  21. protected function run($argument) {
  22. $this->syncService->syncThemAll(function ($url, $ex) {
  23. if ($ex instanceof \Exception) {
  24. $this->logger->error("Error while syncing $url.", [
  25. 'app' => 'fed-sync',
  26. 'exception' => $ex,
  27. ]);
  28. }
  29. });
  30. }
  31. }