stanley-king 3 年之前
父節點
當前提交
c441958d9d
共有 2 個文件被更改,包括 20 次插入14 次删除
  1. 0 2
      helper/queue/iqueue.php
  2. 20 12
      rdispatcher/coall.php

+ 0 - 2
helper/queue/iqueue.php

@@ -303,9 +303,7 @@ abstract class ILooper
 
     public function run()
     {
-        refill\RefillFactory::instance();
         $this->_cid = Swoole\Coroutine::getCid();
-
         $queues = $this->mServer->scan();
         while (true)
         {

+ 20 - 12
rdispatcher/coall.php

@@ -71,7 +71,8 @@ function subscribe_message(&$quit, &$redis, $channels,$looper)
                 continue;
             }
 
-            $ret = $redis->subscribe($channels,function ($redis,$channel,$msg) use(&$quit,$looper)
+            $fLoading = false;
+            $ret = $redis->subscribe($channels,function ($redis,$channel,$msg) use(&$quit,$looper,&$fLoading)
             {
                 Log::record("channel={$channel} msg={$msg}",Log::DEBUG);
                 $content = json_decode($msg,true);
@@ -81,23 +82,29 @@ function subscribe_message(&$quit, &$redis, $channels,$looper)
                 if($quit) return;
 
                 if($type == 'channel' || $type == 'merchant') {
+                    $fLoading = true;
                     $looper->pause();
                     Log::record("start load.....",Log::DEBUG);
                     refill\RefillFactory::instance()->load();
                     Log::record("fini load.....",Log::DEBUG);
                     $looper->resume();
+                    $fLoading = false;
                 }
-                elseif($type == 'ratio') {
-                    $ins = Cache::getInstance('cacheredis');
-                    $val = $ins->get_org('channel_ratios');
-
-                    if(empty($val)) return;
-                    $val = json_decode($val,true);
-                    if(empty($val)) return;
-                    $ratios = $val['ratios'];
-                    if(empty($ratios)) return;
-
-                    refill\RefillFactory::instance()->UpdateRatio($ratios);
+                elseif($type == 'ratio')
+                {
+                    if($fLoading == false)
+                    {
+                        $ins = Cache::getInstance('cacheredis');
+                        $val = $ins->get_org('channel_ratios');
+
+                        if(empty($val)) return;
+                        $val = json_decode($val,true);
+                        if(empty($val)) return;
+                        $ratios = $val['ratios'];
+                        if(empty($ratios)) return;
+
+                        refill\RefillFactory::instance()->UpdateRatio($ratios);
+                    }
                 }
                 else {
                     Log::record("subscribe_message dont not handle mgs:{$channel}-{$type}",Log::DEBUG);
@@ -121,6 +128,7 @@ for ($i = 0; $i < $process_count;$i++)
     $process = new Swoole\Process(function(Swoole\Process $worker)
     {
         Base::run_util();
+        refill\RefillFactory::instance();
         set_error_handler('handle_error');
 
         $sub_quit = false;