1
0

TestParallelAwareJob.php 814 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Test\BackgroundJob;
  7. use OCP\AppFramework\Utility\ITimeFactory;
  8. class TestParallelAwareJob extends \OCP\BackgroundJob\Job {
  9. private $testCase;
  10. /**
  11. * @var callable $callback
  12. */
  13. private $callback;
  14. /**
  15. * @param JobTest $testCase
  16. * @param callable $callback
  17. */
  18. public function __construct(?ITimeFactory $time = null, $testCase = null, $callback = null) {
  19. parent::__construct($time ?? \OC::$server->get(ITimeFactory::class));
  20. $this->setAllowParallelRuns(false);
  21. $this->testCase = $testCase;
  22. $this->callback = $callback;
  23. }
  24. public function run($argument) {
  25. $this->testCase->markRun();
  26. $callback = $this->callback;
  27. $callback($argument);
  28. }
  29. }