e
This commit is contained in:
@@ -47,24 +47,23 @@ abstract class Queue extends Component implements Relyon
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $key
|
* @param $key
|
||||||
* @param Consumer $consumer
|
* @param string $consumer
|
||||||
* @return false|int
|
* @return false|int
|
||||||
* @throws ComponentException
|
* @throws ComponentException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function pop($key, Consumer $consumer)
|
protected function pop($key, string $consumer)
|
||||||
{
|
{
|
||||||
$redis = Snowflake::app()->getRedis();
|
$redis = Snowflake::app()->getRedis();
|
||||||
try {
|
try {
|
||||||
$serialize = serialize($consumer);
|
if (!$redis->lock($hash = md5($consumer))) {
|
||||||
if (!$redis->lock($hash = md5($serialize))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$isExists = $redis->zRevRank($key, $serialize);
|
$isExists = $redis->zRevRank($key, $consumer);
|
||||||
if ($isExists === null) {
|
if ($isExists === null) {
|
||||||
return $redis->unlink($hash);
|
return $redis->unlink($hash);
|
||||||
}
|
}
|
||||||
$redis->zRem($key, $serialize);
|
$redis->zRem($key, $consumer);
|
||||||
return $redis->unlink($hash);
|
return $redis->unlink($hash);
|
||||||
} finally {
|
} finally {
|
||||||
$redis->release();
|
$redis->release();
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ class Complete extends \Queue\Abstracts\Queue
|
|||||||
* @return false|int
|
* @return false|int
|
||||||
* @throws ComponentException
|
* @throws ComponentException
|
||||||
*/
|
*/
|
||||||
public function del(Consumer $consumer)
|
public function del(string $consumer)
|
||||||
{
|
{
|
||||||
return $this->pop(self::QUEUE_COMPLETE, $consumer);
|
return $this->pop(self::QUEUE_COMPLETE, $consumer);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -116,19 +116,18 @@ class Queue extends \Snowflake\Process\Process
|
|||||||
*/
|
*/
|
||||||
private function runner(string $class)
|
private function runner(string $class)
|
||||||
{
|
{
|
||||||
$logger = $this->application->getLogger();
|
|
||||||
try {
|
try {
|
||||||
$rely_on = unserialize($class);
|
$rely_on = unserialize($class);
|
||||||
$this->waiting->del($rely_on);
|
$this->waiting->del($class);
|
||||||
if (!($rely_on instanceof Consumer)) {
|
if (!($rely_on instanceof Consumer)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->running->add($rely_on);
|
$this->running->add($rely_on);
|
||||||
$rely_on->onRunning();
|
$rely_on->onRunning();
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
$logger->write($exception->getMessage(), 'queue');
|
logger()->write($exception->getMessage(), 'queue');
|
||||||
} finally {
|
} finally {
|
||||||
$this->running->del($rely_on);
|
$this->running->del($class);
|
||||||
if (isset($rely_on) && $rely_on instanceof Consumer) {
|
if (isset($rely_on) && $rely_on instanceof Consumer) {
|
||||||
$rely_on->onComplete();
|
$rely_on->onComplete();
|
||||||
$this->complete->add($rely_on);
|
$this->complete->add($rely_on);
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ class Running extends \Queue\Abstracts\Queue
|
|||||||
* @return false|int
|
* @return false|int
|
||||||
* @throws ComponentException
|
* @throws ComponentException
|
||||||
*/
|
*/
|
||||||
public function del(Consumer $consumer)
|
public function del(string $consumer)
|
||||||
{
|
{
|
||||||
return $this->pop(self::QUEUE_RUNNING, $consumer);
|
return $this->pop(self::QUEUE_RUNNING, $consumer);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ class Waiting extends \Queue\Abstracts\Queue
|
|||||||
* @return false|int
|
* @return false|int
|
||||||
* @throws ComponentException
|
* @throws ComponentException
|
||||||
*/
|
*/
|
||||||
public function del(Consumer $consumer)
|
public function del(string $consumer)
|
||||||
{
|
{
|
||||||
return $this->pop(self::QUEUE_WAITING, $consumer);
|
return $this->pop(self::QUEUE_WAITING, $consumer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
defined('APP_PATH') or define('APP_PATH', __DIR__ . '/../../');
|
defined('APP_PATH') or define('APP_PATH', __DIR__ . '/../../');
|
||||||
|
|
||||||
use HttpServer\Http\Response;
|
use HttpServer\Http\Response;
|
||||||
|
use Snowflake\Error\Logger;
|
||||||
|
use Snowflake\Exception\ComponentException;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
use HttpServer\Http\Context;
|
use HttpServer\Http\Context;
|
||||||
use Snowflake\Core\ArrayAccess;
|
use Snowflake\Core\ArrayAccess;
|
||||||
@@ -45,6 +47,20 @@ if (!function_exists('exif_imagetype')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!function_exists('logger')) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Logger
|
||||||
|
* @throws ComponentException
|
||||||
|
*/
|
||||||
|
function logger()
|
||||||
|
{
|
||||||
|
return Snowflake::app()->getLogger();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!function_exists('get_file_extension')) {
|
if (!function_exists('get_file_extension')) {
|
||||||
|
|
||||||
function get_file_extension($filename)
|
function get_file_extension($filename)
|
||||||
|
|||||||
Reference in New Issue
Block a user