1
0

SyncJob.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\Federation;
  27. use OCP\BackgroundJob\TimedJob;
  28. use OCP\AppFramework\Utility\ITimeFactory;
  29. use Psr\Log\LoggerInterface;
  30. class SyncJob extends TimedJob {
  31. protected SyncFederationAddressBooks $syncService;
  32. protected LoggerInterface $logger;
  33. public function __construct(SyncFederationAddressBooks $syncService, LoggerInterface $logger, ITimeFactory $timeFactory) {
  34. parent::__construct($timeFactory);
  35. // Run once a day
  36. $this->setInterval(24 * 60 * 60);
  37. $this->syncService = $syncService;
  38. $this->logger = $logger;
  39. }
  40. protected function run($argument) {
  41. $this->syncService->syncThemAll(function ($url, $ex) {
  42. if ($ex instanceof \Exception) {
  43. $this->logger->info("Error while syncing $url.", [
  44. 'app' => 'fed-sync',
  45. 'exception' => $ex,
  46. ]);
  47. }
  48. });
  49. }
  50. }