1
0

TestParallelAwareJob.php 873 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * Copyright (c) 2014 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 Test\BackgroundJob;
  9. use OCP\AppFramework\Utility\ITimeFactory;
  10. class TestParallelAwareJob extends \OCP\BackgroundJob\Job {
  11. private $testCase;
  12. /**
  13. * @var callable $callback
  14. */
  15. private $callback;
  16. /**
  17. * @param JobTest $testCase
  18. * @param callable $callback
  19. */
  20. public function __construct(ITimeFactory $time = null, $testCase = null, $callback = null) {
  21. parent::__construct($time ?? \OC::$server->get(ITimeFactory::class));
  22. $this->setAllowParallelRuns(false);
  23. $this->testCase = $testCase;
  24. $this->callback = $callback;
  25. }
  26. public function run($argument) {
  27. $this->testCase->markRun();
  28. $callback = $this->callback;
  29. $callback($argument);
  30. }
  31. }