This commit is contained in:
2020-09-11 01:12:32 +08:00
parent e2e0b7319d
commit 67ca557961
3 changed files with 10 additions and 16 deletions
+2 -1
View File
@@ -215,8 +215,9 @@ class Server extends Application
if (!is_string($process)) { if (!is_string($process)) {
continue; continue;
} }
$system = $application->set($process, new $process(Snowflake::app(), $name)); $system = new $process(Snowflake::app(), $name);
$this->baseServer->addProcess($system); $this->baseServer->addProcess($system);
$application->set($process, $system);
} }
} }
+7 -10
View File
@@ -56,16 +56,15 @@ class Queue extends \Snowflake\Process\Process
/** /**
* @param Process $process * @param Process $process
* @throws ComponentException
*/ */
public function onHandler(Process $process) public function onHandler(Process $process)
{ {
$redis = Snowflake::app()->getRedis(); Timer::tick(50, function ($timerId) {
Timer::tick(50, function ($timerId) use ($redis) { $redis = Snowflake::app()->getRedis();
if ($this->shutdown) { if ($this->shutdown) {
return Timer::clear($timerId); return Timer::clear($timerId);
} }
$data = $redis->zRevRangeByScore(Waiting::QUEUE_WAITING, 0, 20); $data = $redis->zRevRange(Waiting::QUEUE_WAITING, 0, 20);
if (empty($data)) { if (empty($data)) {
return 1; return 1;
} }
@@ -97,11 +96,9 @@ class Queue extends \Snowflake\Process\Process
*/ */
private function scheduler($data) private function scheduler($data)
{ {
$scheduler = new Coroutine\Scheduler();
foreach ($data as $datum) { foreach ($data as $datum) {
$scheduler->add([$this, 'runner'], $datum); $this->runner($datum);
} }
$scheduler->start();
if ($this->shutdown === true) { if ($this->shutdown === true) {
Snowflake::shutdown($this); Snowflake::shutdown($this);
} }
@@ -118,8 +115,8 @@ class Queue extends \Snowflake\Process\Process
$logger = $this->application->getLogger(); $logger = $this->application->getLogger();
try { try {
$rely_on = unserialize($class); $rely_on = unserialize($class);
$this->waiting->remove($class); $this->waiting->del($rely_on);
if ($rely_on instanceof Consumer) { if (!($rely_on instanceof Consumer)) {
return; return;
} }
$this->running->add($rely_on); $this->running->add($rely_on);
@@ -127,7 +124,7 @@ class Queue extends \Snowflake\Process\Process
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$logger->write($exception->getMessage(), 'queue'); $logger->write($exception->getMessage(), 'queue');
} finally { } finally {
$this->running->del($class); $this->running->del($rely_on);
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 -5
View File
@@ -38,12 +38,8 @@ class Running extends \Queue\Abstracts\Queue
* @return false|int * @return false|int
* @throws ComponentException * @throws ComponentException
*/ */
public function del(string $consumer) public function del(Consumer $consumer)
{ {
$consumer = unserialize($consumer);
if (!($consumer instanceof Consumer)) {
return true;
}
return $this->pop(self::QUEUE_RUNNING, $consumer); return $this->pop(self::QUEUE_RUNNING, $consumer);
} }