stanley-king 4 anos atrás
pai
commit
7a56e3064c
5 arquivos alterados com 17 adições e 15 exclusões
  1. 1 0
      crontab/index.php
  2. 7 1
      extend/queue.logic.php
  3. 2 2
      extend/queue.php
  4. 4 7
      queue/index.php
  5. 3 5
      queue/queuehandler.php

+ 1 - 0
crontab/index.php

@@ -4,6 +4,7 @@
 namespace think;
 
 // 加载基础文件
+
 require __DIR__ . '/../thinkphp/base.php';
 
 define('BASE_ROOT_PATH',str_replace('/crontab','',dirname(__FILE__)));

+ 7 - 1
extend/queue.logic.php

@@ -1,19 +1,22 @@
 <?php
 
-use think\facade\Log;
 class queue_logic
 {
     public function OpenBox($params) {
+        global $config;
         Log::record($params);
         $box_list[] = $params['box_number'];
+
         $postData['cabinet_code']       = $params['cabinet_number'];
         $postData['box_position_list']  = $box_list;
         $postData['delay_time']         = 0;
+
         $return = http_post($params['req_url'] , $postData);
         $return['code'] = 'ok';
         if($return['code'] != 0){
             $return['value'] = 'error';
         }
+
         $this->push_queue_return($params['ret_queue'] , $config['net_queue']['host'] , $config['net_queue']['port'] , $return);
     }
 
@@ -22,11 +25,13 @@ class queue_logic
         $postData['cabinet_code']       = $params['cabinet_number'];
         $postData['box_position_list']  = $box_list;
         $postData['delay_time']         = 0;
+
         $return = http_post($params['req_url'] , $postData);
         $return['code'] = 'ok';
         if($return['code'] != 0){
             $return['value'] = 'error';
         }
+
         $this->push_queue_return($params['ret_queue'] , $config['net_queue']['host'] , $config['net_queue']['port'] , $return);
     }
 
@@ -35,6 +40,7 @@ class queue_logic
         $postData['cabinet_code']       = $params['cabinet_number'];
         $postData['box_position_list']  = $box_list;
         $postData['delay_time']         = 0;
+
         $return = http_post($params['req_url'] , $postData);
         $return['code'] = 'ok';
         if($return['code'] != 0){

+ 2 - 2
extend/queue.php

@@ -12,12 +12,12 @@ class QueueClient
 {
     private static $queuedb;
 
-    public static function push($queue_name,$host,$port, $value)
+    public static function push($queue_name,$host,$port,$key, $value)
     {
         if (!is_object(self::$queuedb)) {
             self::$queuedb = new QueueDB($queue_name,$host,$port);
         }
-        return self::$queuedb->push(serialize($value));
+        return self::$queuedb->push(serialize([$key=>$value]));
     }
 }
 

+ 4 - 7
queue/index.php

@@ -1,20 +1,17 @@
 <?php
 
-// [ 应用入口文件 ]
-namespace think;
 
-use queuehandler;
-
-// 加载基础文件
-require __DIR__ . '/../thinkphp/base.php';
-echo 11;
 define('BASE_ROOT_PATH',str_replace('/queue','',dirname(__FILE__)));
 define('BASE_PATH',BASE_ROOT_PATH . '/queue');
+define('BASE_DATA_PATH',BASE_ROOT_PATH . '/data');
+define('APP_ID','queue');
 
 require_once(BASE_PATH . '/config.ini.php');
 require_once(BASE_ROOT_PATH . '/extend/queue.php');
 require_once(BASE_ROOT_PATH . '/extend/queue.logic.php');
+require_once(BASE_ROOT_PATH . '/extend/log.php');
 require_once(BASE_PATH . '/queuehandler.php');
 
+Log::record('xxxxxx',Log::DEBUG);
 $handler = new queuehandler();
 $handler->run();

+ 3 - 5
queue/queuehandler.php

@@ -3,7 +3,6 @@ declare(strict_types=0);
 
 //此行代码会导致bug
 //ini_set('default_socket_timeout', -1);
-use think\facade\Log;
 
 class queuehandler
 {
@@ -33,7 +32,6 @@ class queuehandler
             try
             {
                 if ($this->_stop) break;
-                echo 2;
                 $content = $worker->pop($queues, 1);
                 if(is_array($content))
                 {
@@ -41,11 +39,11 @@ class queuehandler
                     $arg = current($content);
 
                     $argstr = json_encode($arg,JSON_UNESCAPED_UNICODE);
-                    Log::record("method={$method} args={$argstr}",'debug');
+                    Log::record("method={$method} args={$argstr}",Log::DEBUG);
 
                     $result = $logic_queue->$method($arg);
                     if (!$result['state']) {
-                        Log::record("{$method} run error: {$result['msg']}",'debug');
+                        Log::record("{$method} run error: {$result['msg']}",Log::DEBUG);
                     }
                 }
             }
@@ -53,7 +51,7 @@ class queuehandler
             {
                 $err = $e->getMessage();
                 $code = $e->getCode();
-                Log::record("QueueDB pop err: code={$code} err={$err}",'debug');
+                Log::record("QueueDB pop err: code={$code} err={$err}",Log::DEBUG);
                 break;
             }
         }