|
@@ -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) {
|