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.

62 lines
1.6 KiB

3 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Robin Appelman <robin@icewind.nl>
  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 OC\BackgroundJob;
  27. use OCP\BackgroundJob\IJobList;
  28. use OCP\ILogger;
  29. /**
  30. * Class QueuedJob
  31. *
  32. * create a background job that is to be executed at an interval
  33. *
  34. * @package OC\BackgroundJob
  35. */
  36. abstract class TimedJob extends Job {
  37. protected $interval = 0;
  38. /**
  39. * set the interval for the job
  40. *
  41. * @param int $interval
  42. */
  43. public function setInterval($interval) {
  44. $this->interval = $interval;
  45. }
  46. /**
  47. * run the job if
  48. *
  49. * @param IJobList $jobList
  50. * @param ILogger|null $logger
  51. */
  52. public function execute($jobList, ILogger $logger = null) {
  53. if ((time() - $this->lastRun) > $this->interval) {
  54. parent::execute($jobList, $logger);
  55. }
  56. }
  57. }