作者 邓超

x

@@ -100,8 +100,38 @@ class SyncToEsCmd { @@ -100,8 +100,38 @@ class SyncToEsCmd {
100 protected $bulkData; 100 protected $bulkData;
101 101
102 102
  103 + public function checkfile(){
  104 +
  105 + if(redis()->add('sync_es_fail_load_lock',1,10)){
  106 + $body = file_get_contents(LOG_PATH."/sync_es_fail.log");
  107 + if($body){
  108 + // 备份文件
  109 + if(file_put_contents(LOG_PATH."/sync_es_fail.".date('Y-m-d H:i:s').".log",$body)){
  110 +
  111 + file_put_contents(LOG_PATH."/sync_es_fail.log",'');
  112 + $body = explode("\n",$body);
  113 + echo count($body)." 个\n";
  114 + // 清空当前文件
  115 +
  116 + foreach ($body as $i=>$id){
  117 + if($id) redis()->rPush('sync_to_es', trim($id));
  118 + }
  119 + echo 'end';
  120 + }
  121 +
  122 + }
  123 + }
  124 +
  125 +
  126 +
  127 + }
  128 +
103 public function handler(){ 129 public function handler(){
104 130
  131 + $this->checkfile();
  132 +
  133 + sleep(5);
  134 +
105 $this->es = es('email_lists_copy'); // 第二个库 新 135 $this->es = es('email_lists_copy'); // 第二个库 新
106 136
107 $this->bulkData = new \Lib\Es\BulkData(); 137 $this->bulkData = new \Lib\Es\BulkData();