timedjob.php 807 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\BackgroundJob;
  9. /**
  10. * Class QueuedJob
  11. *
  12. * create a background job that is to be executed at an interval
  13. *
  14. * @package OC\BackgroundJob
  15. */
  16. abstract class TimedJob extends Job {
  17. protected $interval = 0;
  18. /**
  19. * set the interval for the job
  20. *
  21. * @param int $interval
  22. */
  23. public function setInterval($interval) {
  24. $this->interval = $interval;
  25. }
  26. /**
  27. * run the job if
  28. *
  29. * @param JobList $jobList
  30. * @param \OC\Log $logger
  31. */
  32. public function execute($jobList, $logger = null) {
  33. if ((time() - $this->lastRun) > $this->interval) {
  34. parent::execute($jobList, $logger);
  35. }
  36. }
  37. }