您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CronBus.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  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
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OC\Command;
  27. use OCP\Command\ICommand;
  28. class CronBus extends AsyncBus {
  29. /**
  30. * @var \OCP\BackgroundJob\IJobList
  31. */
  32. private $jobList;
  33. /**
  34. * @param \OCP\BackgroundJob\IJobList $jobList
  35. */
  36. public function __construct($jobList) {
  37. $this->jobList = $jobList;
  38. }
  39. protected function queueCommand($command) {
  40. $this->jobList->add($this->getJobClass($command), $this->serializeCommand($command));
  41. }
  42. /**
  43. * @param \OCP\Command\ICommand | callable $command
  44. * @return string
  45. */
  46. private function getJobClass($command) {
  47. if ($command instanceof \Closure) {
  48. return ClosureJob::class;
  49. } elseif (is_callable($command)) {
  50. return CallableJob::class;
  51. } elseif ($command instanceof ICommand) {
  52. return CommandJob::class;
  53. } else {
  54. throw new \InvalidArgumentException('Invalid command');
  55. }
  56. }
  57. /**
  58. * @param \OCP\Command\ICommand | callable $command
  59. * @return string
  60. */
  61. private function serializeCommand($command) {
  62. if ($command instanceof \Closure) {
  63. return \Opis\Closure\serialize($command);
  64. } elseif (is_callable($command) or $command instanceof ICommand) {
  65. return \Opis\Closure\serialize($command);
  66. } else {
  67. throw new \InvalidArgumentException('Invalid command');
  68. }
  69. }
  70. }