From 5815f9db1221eedeb76e865a13d2585e69e60861 Mon Sep 17 00:00:00 2001 From: Virgil-Adrian Teaca Date: Mon, 30 Apr 2018 18:05:03 +0300 Subject: [PATCH] Improve the Queue Service --- src/Foundation/Application.php | 2 +- src/Queue/Jobs/SyncJob.php | 24 +++++++++--------------- src/Queue/Queues/SyncQueue.php | 17 +++++++++++------ 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/Foundation/Application.php b/src/Foundation/Application.php index c234f447..64d50e90 100644 --- a/src/Foundation/Application.php +++ b/src/Foundation/Application.php @@ -41,7 +41,7 @@ class Application extends Container implements ResponsePreparerInterface * * @var string */ - const VERSION = '4.0.46'; + const VERSION = '4.0.47'; /** * Indicates if the application has "booted". diff --git a/src/Queue/Jobs/SyncJob.php b/src/Queue/Jobs/SyncJob.php index 87504c52..7c21e5f0 100644 --- a/src/Queue/Jobs/SyncJob.php +++ b/src/Queue/Jobs/SyncJob.php @@ -23,7 +23,8 @@ class SyncJob extends Job * * @var string */ - protected $data; + protected $payload; + /** * Create a new job instance. @@ -33,10 +34,10 @@ class SyncJob extends Job * @param string $data * @return void */ - public function __construct(Container $container, $job, $data = '') + public function __construct(Container $container, $payload, $queue = '') { - $this->job = $job; - $this->data = $data; + $this->payload = $payload; + $this->queue = $queue; $this->container = $container; } @@ -47,16 +48,9 @@ public function __construct(Container $container, $job, $data = '') */ public function handle() { - $data = json_decode($this->data, true); - - if ($this->job instanceof Closure) { - call_user_func($this->job, $this, $data); - } else { - $this->resolveAndHandle(array( - 'job' => $this->job, - 'data' => $data - )); - } + $payload = json_decode($this->getRawBody(), true); + + $this->resolveAndHandle($payload); } /** @@ -66,7 +60,7 @@ public function handle() */ public function getRawBody() { - // + return $this->payload; } /** diff --git a/src/Queue/Queues/SyncQueue.php b/src/Queue/Queues/SyncQueue.php index b2371393..9b042855 100644 --- a/src/Queue/Queues/SyncQueue.php +++ b/src/Queue/Queues/SyncQueue.php @@ -19,7 +19,9 @@ class SyncQueue extends Queue implements QueueInterface */ public function push($job, $data = '', $queue = null) { - $this->resolveJob($job, json_encode($data))->handle(); + $queueJob = $this->resolveJob($this->createPayload($job, $data, $queue), $queue); + + $queueJob->handle(); return 0; } @@ -58,18 +60,21 @@ public function later($delay, $job, $data = '', $queue = null) * @param string $queue * @return \Nova\Queue\Jobs\Job|null */ - public function pop($queue = null) {} + public function pop($queue = null) + { + // + } /** * Resolve a Sync job instance. * - * @param string $job - * @param string $data + * @param string $payload + * @param string $queues * @return \Nova\Queue\Jobs\SyncJob */ - protected function resolveJob($job, $data) + protected function resolveJob($payload, $queue) { - return new SyncJob($this->container, $job, $data); + return new SyncJob($this->container, $payload, $queue); } }