From 0e160f2133c8edb6d11015e8a2495765327b4986 Mon Sep 17 00:00:00 2001 From: Fractal Zombie Date: Wed, 19 Dec 2018 21:35:50 +0200 Subject: [PATCH] Refactoring. Removes old laravel|lumen versions. Added support for 5.6|5.7 laravel|lumen. Added to config support for hot reload (Next PR). --- src/Coroutine/Connectors/MySqlConnector.php | 1 - src/Task/SwooleTaskQueue.php | 51 ++++++++++++--------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/Coroutine/Connectors/MySqlConnector.php b/src/Coroutine/Connectors/MySqlConnector.php index ebcb052b..7082d761 100644 --- a/src/Coroutine/Connectors/MySqlConnector.php +++ b/src/Coroutine/Connectors/MySqlConnector.php @@ -26,7 +26,6 @@ class MySqlConnector extends BaseConnector */ protected function createPdoConnection($dsn, $username, $password, $options) { - //TODO I'm thinking make it out by MysqlPool return new SwoolePDO($dsn, $username, $password, $options); } diff --git a/src/Task/SwooleTaskQueue.php b/src/Task/SwooleTaskQueue.php index 2cb76603..0a28fedf 100644 --- a/src/Task/SwooleTaskQueue.php +++ b/src/Task/SwooleTaskQueue.php @@ -2,11 +2,15 @@ namespace SwooleTW\Http\Task; + use Exception; -use Swoole\Timer; -use Illuminate\Queue\Queue; use Illuminate\Contracts\Queue\Queue as QueueContract; +use Illuminate\Queue\Queue; +use Swoole\Timer; +/** + * Class SwooleTaskQueue (5.7) + */ class SwooleTaskQueue extends Queue implements QueueContract { /** @@ -19,7 +23,7 @@ class SwooleTaskQueue extends Queue implements QueueContract /** * Create Async Task instance. * - * @param \Swoole\Http\Server $swoole + * @param \Swoole\Http\Server $swoole */ public function __construct($swoole) { @@ -29,9 +33,10 @@ public function __construct($swoole) /** * Push a new job onto the queue. * - * @param string|object $job - * @param mixed $data - * @param string $queue + * @param string|object $job + * @param mixed $data + * @param string $queue + * * @return mixed */ public function push($job, $data = '', $queue = null) @@ -42,24 +47,25 @@ public function push($job, $data = '', $queue = null) /** * Push a raw payload onto the queue. * - * @param string $payload - * @param string $queue - * @param array $options + * @param string $payload + * @param string $queue + * @param array $options + * * @return mixed */ public function pushRaw($payload, $queue = null, array $options = []) { - //wiki https://wiki.swoole.com/wiki/page/134.html, task($data,$dst_worker_id), $dst_worker_id should be default -1 - return $this->swoole->task($payload, (!is_numeric($queue) || $queue < 0) ? -1 : (int)$queue); + return $this->swoole->task($payload, !is_numeric($queue) ? 1 : (int)$queue); } /** * Push a new job onto the queue after a delay. * - * @param \DateTimeInterface|\DateInterval|int $delay - * @param string|object $job - * @param mixed $data - * @param string $queue + * @param \DateTimeInterface|\DateInterval|int $delay + * @param string|object $job + * @param mixed $data + * @param string $queue + * * @return mixed */ public function later($delay, $job, $data = '', $queue = null) @@ -72,12 +78,13 @@ public function later($delay, $job, $data = '', $queue = null) /** * Create a typical, string based queue payload array. * - * @param string $job - * @param mixed $data + * @param string $job + * @param string $queue + * @param mixed $data * - * @throws Expcetion + * @throws \Exception */ - protected function createStringPayload($job, $data) + protected function createStringPayload($job, $queue, $data) { throw new Exception('Unsupported empty data'); } @@ -85,7 +92,8 @@ protected function createStringPayload($job, $data) /** * Get the size of the queue. * - * @param string $queue + * @param string $queue + * * @return int */ public function size($queue = null) @@ -96,7 +104,8 @@ public function size($queue = null) /** * Pop the next job off of the queue. * - * @param string $queue + * @param string $queue + * * @return \Illuminate\Contracts\Queue\Job|null */ public function pop($queue = null)