qiushiyong 11 months ago
parent
commit
afa62c258e
1 changed files with 14 additions and 3 deletions
  1. 14 3
      App/Crontab/ElasticSearchGoodsNewCrontab2.php

+ 14 - 3
App/Crontab/ElasticSearchGoodsNewCrontab2.php

@@ -17,7 +17,9 @@ use EasySwoole\EasySwoole\Logger;
 class ElasticSearchGoodsNewCrontab2 implements JobInterface
 {
 
-    protected $time = 60 * 30; //xx内更新或新增的商品同步到es
+    protected $time = 60 * 20; //xx内更新或新增的商品同步到es
+
+    protected $ids = [];
 
     public function jobName(): string
     {
@@ -29,8 +31,9 @@ class ElasticSearchGoodsNewCrontab2 implements JobInterface
     {
         // 定义执行规则 根据 Crontab 来定义
         // 这里是每10分钟执行 1 次
-        return '*/10 * * * *';
+//        return '*/10 * * * *';
 //        return '* * * * *';
+        return '*/3 * * * *';
     }
 
     public function run()
@@ -45,10 +48,12 @@ class ElasticSearchGoodsNewCrontab2 implements JobInterface
         $page = 1;
         while (true) {
             if ($page > 20) {
+                $this->ids = [];
                 break;
             }
             $goods = $this->getUpdateGoods($page);
             if (!$goods) {
+                $this->ids = [];
                 break;
             } else {
                 $page++;
@@ -75,7 +80,13 @@ class ElasticSearchGoodsNewCrontab2 implements JobInterface
         $size = 50;
         $offset = ($page - 1) * $size;
 
-        $ids = array_unique(array_merge($this->getGoodsIdFromPool(), $this->getGoodsIdFromOperators_goods()));
+        if ($this->ids) {
+            $ids = $this->ids;
+        } else {
+            $ids = array_unique(array_merge($this->getGoodsIdFromPool(), $this->getGoodsIdFromOperators_goods()));
+            $this->ids = $ids;
+        }
+//        $ids = array_unique(array_merge($this->getGoodsIdFromPool(), $this->getGoodsIdFromOperators_goods()));
         if (!$ids) {
             return [];
         }