stanley-king před 3 roky
rodič
revize
fe6c5c0a96

+ 6 - 1
helper/message/publisher.php

@@ -235,5 +235,10 @@ class publisher
             $this->mRedis->publish('refill',serialize(['type'=>'merchant','value' => 0]));
         }
     }
-
+    public function modify_refill_ratio()
+    {
+        if($this->mConnected) {
+            $this->mRedis->publish('refill',serialize(['type'=>'ratio','value' => 0]));
+        }
+    }
 }

+ 1 - 0
helper/refill/RefillBase.php

@@ -94,6 +94,7 @@ class RefillBase
 
             $order_info = $mod_order->getOrderInfo(['order_id' => $order_id],'*',true,true);
             $order_state = intval($order_info['order_state']);
+
             if ($order_state != ORDER_STATE_SEND) {
                 $tran->commit();
                 return false;

+ 0 - 2
helper/statistics/stat_refill.php

@@ -76,8 +76,6 @@ class stat_refill
         }
     }
 
-
-
     private function system_stat($day_time)
     {
         $cond = [

+ 5 - 52
rdispatcher/codispatcher.php

@@ -63,7 +63,6 @@ function subscribe_message(&$quit, &$redis, $channels)
             if(!$ret) {
                 Log::record("subscribe_message cannot connet redis.",Log::DEBUG);
                 $redis->close();
-                Swoole\Coroutine::sleep(1);
             }
             elseif($redis->subscribe($channels))
             {
@@ -80,6 +79,10 @@ function subscribe_message(&$quit, &$redis, $channels)
                         Log::record("subscribe_message recv mgs:{$sub_type}-{$channel}-{$type}",Log::DEBUG);
                         refill\RefillFactory::instance()->load();
                     }
+                    elseif($type == 'ratio') {
+                        Log::record("subscribe_message recv mgs:{$sub_type}-{$channel}-{$type}",Log::DEBUG);
+                        refill\RefillFactory::instance()->UpdateRatio();
+                    }
                 }
                 Log::record("subscribe_message redis recv timeout",Log::DEBUG);
             }
@@ -97,55 +100,11 @@ function subscribe_message(&$quit, &$redis, $channels)
     $quit = true;
 }
 
-function ratio_update(&$quit)
-{
-    //每分钟的第0秒 将上一分钟的数据,写入HD5File。
-    //每分钟的第2秒 统计之前的数据
-    //每分钟的第3秒触发更新 成功率统计数据
-    $cur_min = 0;
-    while (!$quit)
-    {
-        Log::record("ratio_update start calc quit =" . strbool($quit),Log::DEBUG);
-        Log::record("ratio_update start sleep",Log::DEBUG);
-//        Co::sleep(1);
-        Swoole\Coroutine\System::sleep(1);
-//        sleep(1);
-        Log::record("ratio_update end sleep",Log::DEBUG);
-
-//        for ($i = 0; $i < 61; $i++) {
-//            $cur_time = time();
-//            $time_sec = $cur_time;
-//            $next_min = $time_sec - $time_sec % 60;
-//
-//            if($quit) break;
-//            if($next_min > $cur_min && $time_sec % 60 == 3) {
-//                $cur_min = $next_min;
-//                break;
-//            } else {
-//                Log::record("ratio_update start sleep",Log::DEBUG);
-//                Swoole\Coroutine::sleep(1);
-//                Log::record("ratio_update end sleep",Log::DEBUG);
-//            }
-//        }
-
-
-
-//        if(!$quit) {
-//            refill\RefillFactory::instance()->UpdateRatio();
-//        }
-    }
-
-    Log::record("ratio_update quit =". strbool($quit),Log::DEBUG);
-    $quit = true;
-}
-
 $workers = [];
 for ($i = 0; $i < $process_count;$i++)
 {
     $process = new Swoole\Process(function(Swoole\Process $worker)
     {
-        Co::set(['hook_flags' => SWOOLE_HOOK_NATIVE_CURL|SWOOLE_HOOK_SLEEP]);
-
         Base::run_util();
         set_error_handler('handle_error');
 
@@ -155,24 +114,18 @@ for ($i = 0; $i < $process_count;$i++)
             subscribe_message($sub_quit,$sub_redis,['refill']);
         });
 
-        $ratio_quit = false;
-        go(function () use (&$ratio_quit) {
-            ratio_update($ratio_quit);
-        });
-
         $looper = new processor(true);
         go(function () use ($looper) {
             $looper->run();
         });
 
-        Swoole\Process::signal(SIGTERM, function($signal_num) use ($worker,&$sub_quit,$sub_redis,&$ratio_quit,$looper)
+        Swoole\Process::signal(SIGTERM, function($signal_num) use ($worker,&$sub_quit,$sub_redis,$looper)
         {
             Log::record("signal call SIGTERM begin = $signal_num, #{$worker->pid}",Log::DEBUG);
 
             set_error_handler(null);
             try {
                 $sub_quit = true;
-                $ratio_quit = true;
                 $sub_redis->close();
             }
             catch(Exception $ex) {

+ 0 - 3
rdispatcher/proxy.php

@@ -92,9 +92,6 @@ class proxy
                     if($order_id > 0) {
                         $refill_order->edit($order_id, ['is_retrying' => 1]);
                     }
-                    if(defined('USE_COROUTINE') && USE_COROUTINE && $errcode == refill\errcode::PROVIDER_OVERLOAD) {
-                        \Swoole\Coroutine::sleep(1);
-                    }
                     refill\util::push_add($params);
                 }
             }

+ 43 - 0
server/ratio_pub.php

@@ -0,0 +1,43 @@
+<?php
+
+
+function ratio_update(&$quit)
+{
+    //每分钟的第0秒 将上一分钟的数据,写入HD5File。
+    //每分钟的第2秒 统计之前的数据
+    //每分钟的第3秒触发更新 成功率统计数据
+    $cur_min = 0;
+    while (!$quit) {
+        Log::record("ratio_update start calc quit =" . strbool($quit), Log::DEBUG);
+        Log::record("ratio_update start sleep", Log::DEBUG);
+//        Co::sleep(1);
+        Swoole\Coroutine\System::sleep(1);
+//        sleep(1);
+        Log::record("ratio_update end sleep", Log::DEBUG);
+    }
+}
+
+//        for ($i = 0; $i < 61; $i++) {
+//            $cur_time = time();
+//            $time_sec = $cur_time;
+//            $next_min = $time_sec - $time_sec % 60;
+//
+//            if($quit) break;
+//            if($next_min > $cur_min && $time_sec % 60 == 3) {
+//                $cur_min = $next_min;
+//                break;
+//            } else {
+//                Log::record("ratio_update start sleep",Log::DEBUG);
+//                Swoole\Coroutine::sleep(1);
+//                Log::record("ratio_update end sleep",Log::DEBUG);
+//            }
+//        }
+
+//        if(!$quit) {
+//            refill\RefillFactory::instance()->UpdateRatio();
+//        }
+//    }
+//
+//    Log::record("ratio_update quit =". strbool($quit),Log::DEBUG);
+//    $quit = true;
+//}