Просмотр исходного кода

Merge branch 'laravel' of https://github.com/visuddhinanda/mint into laravel

visuddhinanda 2 лет назад
Родитель
Сommit
8f3bf3cd21

+ 3 - 1
app/Console/Commands/ExportChannel.php

@@ -45,7 +45,8 @@ class ExportChannel extends Command
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
-        $exportFile = storage_path('app/public/export/offline/sentence-'.date("Y-m-d").'.db3');
+        Log::debug('task export offline channel-table start');
+        $exportFile = storage_path('app/public/export/offline/wikipali-offline-'.date("Y-m-d").'.db3');
         $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
         $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
         $dbh->beginTransaction();
@@ -80,6 +81,7 @@ class ExportChannel extends Command
         }
         $dbh->commit();
         $bar->finish();
+        Log::debug('task export offline channel-table finished');
         return 0;
     }
 }

+ 2 - 0
app/Console/Commands/ExportChapter.php

@@ -46,6 +46,7 @@ class ExportChapter extends Command
      */
     public function handle()
     {
+        Log::debug('task export offline chapter-table start');
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
@@ -175,6 +176,7 @@ class ExportChapter extends Command
             $this->error($data['code'].'-'.$data['message']);
         }
 
+        Log::debug('task export offline chapter-table finished');
         return 0;
     }
 }

+ 3 - 1
app/Console/Commands/ExportChapterIndex.php

@@ -42,10 +42,11 @@ class ExportChapterIndex extends Command
      */
     public function handle()
     {
+        Log::debug('task export offline chapter-index-table start');
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
-        $exportFile = storage_path('app/public/export/offline/sentence-'.date("Y-m-d").'.db3');
+        $exportFile = storage_path('app/public/export/offline/wikipali-offline-'.date("Y-m-d").'.db3');
         $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
         $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
         $dbh->beginTransaction();
@@ -83,6 +84,7 @@ class ExportChapterIndex extends Command
         }
         $dbh->commit();
         $bar->finish();
+        Log::debug('task export offline chapter-index-table finished');
         return 0;
     }
 }

+ 4 - 1
app/Console/Commands/ExportCreateDb.php

@@ -4,6 +4,7 @@ namespace App\Console\Commands;
 
 use Illuminate\Console\Command;
 use Illuminate\Support\Facades\Storage;
+use Illuminate\Support\Facades\Log;
 
 class ExportCreateDb extends Command
 {
@@ -38,12 +39,13 @@ class ExportCreateDb extends Command
      */
     public function handle()
     {
+        Log::debug('task export offline create-db start');
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
         $sqlPath = database_path('export/sentence.sql');
         $exportDir = storage_path('app/public/export/offline');
-        $exportFile = $exportDir.'/sentence-'.date("Y-m-d").'.db3';
+        $exportFile = $exportDir.'/wikipali-offline-'.date("Y-m-d").'.db3';
         $file = fopen($exportFile,'w');
         fclose($file);
         $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
@@ -55,6 +57,7 @@ class ExportCreateDb extends Command
         foreach ($_arr as $_value) {
             $dbh->query($_value . ';');
         }
+        Log::debug('task export offline create-db finished');
         return 0;
     }
 }

+ 8 - 0
app/Console/Commands/ExportOffline.php

@@ -5,6 +5,7 @@ namespace App\Console\Commands;
 use Illuminate\Console\Command;
 use Illuminate\Support\Facades\Storage;
 use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Log;
 
 class ExportOffline extends Command
 {
@@ -65,6 +66,7 @@ class ExportOffline extends Command
         //导出channel
         $this->info('channel');
         $this->call('export:channel');
+        
         //tag
         $this->info('tag');
         $this->call('export:tag');
@@ -83,8 +85,14 @@ class ExportOffline extends Command
         $this->call('export:sentence',['--type'=>'original']);
 
         $this->info('zip');
+        
         $exportPath = 'app/public/export/offline';
         $exportFile = 'wikipali-offline-'.date("Y-m-d").'.db3';
+        Log::debug('zip db file {filename} {format}',
+                    [
+                        'filename'=>$exportFile,
+                        'format'=>$this->argument('format')
+                    ]);
         switch ($this->argument('format')) {
             case '7z':
                 $zipFile = $exportFile . ".7z";

+ 3 - 1
app/Console/Commands/ExportPalitext.php

@@ -40,10 +40,11 @@ class ExportPalitext extends Command
      */
     public function handle()
     {
+        Log::debug('task export offline palitext-table start');
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
-        $exportFile = storage_path('app/public/export/offline/sentence-'.date("Y-m-d").'.db3');
+        $exportFile = storage_path('app/public/export/offline/wikipali-offline-'.date("Y-m-d").'.db3');
         $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
         $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
         $dbh->beginTransaction();
@@ -79,6 +80,7 @@ class ExportPalitext extends Command
         }
         $dbh->commit();
         $bar->finish();
+        Log::debug('task: export offline palitext-table finished');
 
         return 0;
     }

+ 3 - 1
app/Console/Commands/ExportSentence.php

@@ -44,6 +44,7 @@ class ExportSentence extends Command
      */
     public function handle()
     {
+        Log::debug('task export offline sentence-table start');
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
@@ -71,7 +72,7 @@ class ExportSentence extends Command
         }
 
 
-        $exportFile = storage_path('app/public/export/offline/sentence-'.date("Y-m-d").'.db3');
+        $exportFile = storage_path('app/public/export/offline/wikipali-offline-'.date("Y-m-d").'.db3');
         $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
         $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
         $dbh->beginTransaction();
@@ -123,6 +124,7 @@ class ExportSentence extends Command
         }
         $dbh->commit();
         $bar->finish();
+        Log::debug('task export sentence finished');
         return 0;
     }
 }

+ 4 - 1
app/Console/Commands/ExportTag.php

@@ -40,10 +40,11 @@ class ExportTag extends Command
      */
     public function handle()
     {
+        Log::debug('task: export offline data tag-table start');
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
-        $exportFile = storage_path('app/public/export/offline/sentence-'.date("Y-m-d").'.db3');
+        $exportFile = storage_path('app/public/export/offline/wikipali-offline-'.date("Y-m-d").'.db3');
         $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
         $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
         $dbh->beginTransaction();
@@ -72,6 +73,8 @@ class ExportTag extends Command
         }
         $dbh->commit();
         $bar->finish();
+        Log::debug('task: export offline data tag-table start');
+
         return 0;
     }
 }

+ 3 - 1
app/Console/Commands/ExportTagmap.php

@@ -40,10 +40,11 @@ class ExportTagmap extends Command
      */
     public function handle()
     {
+        Log::debug('task: export offline tagmap-table start');
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
-        $exportFile = storage_path('app/public/export/offline/sentence-'.date("Y-m-d").'.db3');
+        $exportFile = storage_path('app/public/export/offline/wikipali-offline-'.date("Y-m-d").'.db3');
         $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
         $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
         $dbh->beginTransaction();
@@ -68,6 +69,7 @@ class ExportTagmap extends Command
         }
         $dbh->commit();
         $bar->finish();
+        Log::debug('task: export offline tagmap-table finished');
         return 0;
     }
 }

+ 3 - 1
app/Console/Commands/ExportTerm.php

@@ -40,10 +40,11 @@ class ExportTerm extends Command
      */
     public function handle()
     {
+        Log::debug('task export offline term-table start');
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
-        $exportFile = storage_path('app/public/export/offline/sentence-'.date("Y-m-d").'.db3');
+        $exportFile = storage_path('app/public/export/offline/wikipali-offline-'.date("Y-m-d").'.db3');
         $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
         $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
         $dbh->beginTransaction();
@@ -91,6 +92,7 @@ class ExportTerm extends Command
         }
         $dbh->commit();
         $bar->finish();
+        Log::debug('task export offline term-table finished');
         return 0;
     }
 }

+ 1 - 0
app/Console/Commands/MqDiscussion.php

@@ -52,6 +52,7 @@ class MqDiscussion extends Command
         $exchange = 'router';
         $queue = 'discussion';
         $this->info(" [*] Waiting for {$queue}. To exit press CTRL+C");
+        Log::info("discussion worker start . Waiting for {$queue}. ");
         Mq::worker($exchange,$queue,function ($message){
             Log::info('mq discussion start {message}',['message'=>json_encode($message,JSON_UNESCAPED_UNICODE)]);
             $result = 0;

+ 1 - 1
app/Console/Commands/TestMq.php

@@ -16,7 +16,7 @@ class TestMq extends Command
      *
      * @var string
      */
-    protected $signature = 'test:mq {--discussion}';
+    protected $signature = 'test:mq {--discussion=}';
 
     /**
      * The console command description.

+ 2 - 3
app/Http/Api/Mq.php

@@ -21,8 +21,7 @@ class Mq{
             return $connection;
     }
     public static function publish(string $channelName, $message){
-                //一对一
-
+       //一对一
         try{
             Log::debug('mq start {channel} {message}',['channel'=>$channelName,'message'=>$message]);
             $host = config("queue.connections.rabbitmq.host");
@@ -111,7 +110,7 @@ class Mq{
                 try{
                     $result = $callback(json_decode($message->body));
                     if($result !== 0){
-                        throw new \Exception('error');
+                        throw new \Exception('task error');
                     }
                 }catch(\Exception $e){
                     // push to issues

+ 6 - 5
documents/php/mq.md

@@ -4,9 +4,10 @@ all of workers in app/Console/Commands
 
 **run**: `php artisan <worker-name>`
 
-workers name :
+```bash
+php artisan mq:discussion
+php artisan mq:pr
+php artisan mq:progress
+php artisan mq:wbw.analyses
+```
 
-1. mq:discussion
-2. mq:pr
-3. mq:progress
-4. mq:wbw.analyses