summaryrefslogtreecommitdiffstats
path: root/lib/private/Command/AsyncBus.php
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-08-24 16:06:37 +0200
committerRobin Appelman <robin@icewind.nl>2017-08-24 16:06:37 +0200
commit9731350acef75931ccbeafa054b40afe8189653f (patch)
tree3da1e286c8ab55882daa05223f9987fae86c8c50 /lib/private/Command/AsyncBus.php
parentae0789ef433adad73bdf77c57b8ead5616ed99fe (diff)
downloadnextcloud-server-9731350acef75931ccbeafa054b40afe8189653f.tar.gz
nextcloud-server-9731350acef75931ccbeafa054b40afe8189653f.zip
split async test bus for easier subclassing
Diffstat (limited to 'lib/private/Command/AsyncBus.php')
-rw-r--r--lib/private/Command/AsyncBus.php55
1 files changed, 9 insertions, 46 deletions
diff --git a/lib/private/Command/AsyncBus.php b/lib/private/Command/AsyncBus.php
index fb3cbee7240..2dffc9c784d 100644
--- a/lib/private/Command/AsyncBus.php
+++ b/lib/private/Command/AsyncBus.php
@@ -24,17 +24,11 @@ namespace OC\Command;
use OCP\Command\IBus;
use OCP\Command\ICommand;
-use SuperClosure\Serializer;
/**
* Asynchronous command bus that uses the background job system as backend
*/
-class AsyncBus implements IBus {
- /**
- * @var \OCP\BackgroundJob\IJobList
- */
- private $jobList;
-
+abstract class AsyncBus implements IBus {
/**
* List of traits for command which require sync execution
*
@@ -43,26 +37,26 @@ class AsyncBus implements IBus {
private $syncTraits = [];
/**
- * @param \OCP\BackgroundJob\IJobList $jobList
- */
- public function __construct($jobList) {
- $this->jobList = $jobList;
- }
-
- /**
* Schedule a command to be fired
*
* @param \OCP\Command\ICommand | callable $command
*/
public function push($command) {
if ($this->canRunAsync($command)) {
- $this->jobList->add($this->getJobClass($command), $this->serializeCommand($command));
+ $this->queueCommand($command);
} else {
$this->runCommand($command);
}
}
/**
+ * Queue a command in the bus
+ *
+ * @param \OCP\Command\ICommand | callable $command
+ */
+ abstract protected function queueCommand($command);
+
+ /**
* Require all commands using a trait to be run synchronous
*
* @param string $trait
@@ -84,37 +78,6 @@ class AsyncBus implements IBus {
/**
* @param \OCP\Command\ICommand | callable $command
- * @return string
- */
- private function getJobClass($command) {
- if ($command instanceof \Closure) {
- return 'OC\Command\ClosureJob';
- } else if (is_callable($command)) {
- return 'OC\Command\CallableJob';
- } else if ($command instanceof ICommand) {
- return 'OC\Command\CommandJob';
- } else {
- throw new \InvalidArgumentException('Invalid command');
- }
- }
-
- /**
- * @param \OCP\Command\ICommand | callable $command
- * @return string
- */
- private function serializeCommand($command) {
- if ($command instanceof \Closure) {
- $serializer = new Serializer();
- return $serializer->serialize($command);
- } else if (is_callable($command) or $command instanceof ICommand) {
- return serialize($command);
- } else {
- throw new \InvalidArgumentException('Invalid command');
- }
- }
-
- /**
- * @param \OCP\Command\ICommand | callable $command
* @return bool
*/
private function canRunAsync($command) {