xielin преди 5 години
родител
ревизия
cf837803b6
променени са 2 файла, в които са добавени 8 реда и са изтрити 104 реда
  1. 0 103
      app/Console/Commands/VirusRule.php
  2. 8 1
      app/Console/Kernel.php

+ 0 - 103
app/Console/Commands/VirusRule.php

@@ -1,103 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019-05-13
- * Time: 10:52
- */
-
-namespace App\Console\Commands;
-
-use Illuminate\Console\Command;
-use Illuminate\Support\Facades\Log;
-use PhpAmqpLib\Connection\AMQPStreamConnection;
-
-class VirusRule extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'virus:rule';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = '订阅VIRUS事件通知';
-
-    protected $connection;
-    protected $channel;
-
-    /**
-     * Create a new command instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        parent::__construct();
-    }
-
-    public function getConnection()
-    {
-        $conn = false;
-        if ($this->connection) {
-            return $this->connection;
-        }
-        for ($i = 0; $i < 3; $i++) {
-            $connection = $this->createConn();
-            if ($connection) {
-                $conn = $connection;
-                break;
-            }
-            Log::info("create amqp conn retry=" . $i);
-        }
-        return $conn;
-    }
-
-    public function createConn()
-    {
-        try {
-            $connection = new AMQPStreamConnection(env('MQ_HOST'), env('MQ_PORT'), env('MQ_USERNAME'), env('MQ_PWD'), env('MQ_VHOST'));
-        } catch (\Exception $exception) {
-            Log::info("AMQP connection Error" . $exception->getMessage());
-            $connection = false;
-        }
-        return $connection;
-    }
-
-    /**
-     * Execute the console command.
-     *
-     * @return mixed
-     */
-    public function handle()
-    {
-        //监听virus队列
-        $this->queue = 'virus_';
-        $this->connection = $this->getConnection();
-        $this->channel = $this->connection->channel();
-        $this->channel->exchange_declare($this->queue, 'fanout', false, true, false);
-
-        $queue_name = $this->queue.'-community-service';
-        $this->channel->queue_declare($queue_name, false, true, false, false);
-        $this->channel->queue_bind($queue_name, $this->queue);
-        $callback = function ($msg) {
-            $data = \GuzzleHttp\json_decode($msg->body,true);
-            $this->line(date('Y-m-d H:i:s')."收到数据---------$msg->body-----------");
-            $result = $this->productCartRepository->deleteCarts($data);
-            $this->line(date('Y-m-d H:i:s')."返回---------$result-----------");
-            $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
-        };
-        $this->channel->basic_qos(null, 1, null);
-        $this->channel->basic_consume($queue_name, '', false, false, false, false, $callback);
-        while (count($this->channel->callbacks)) {
-            $this->channel->wait();
-        }
-        $this->channel->close();
-        $this->connection->close();
-    }
-}

+ 8 - 1
app/Console/Kernel.php

@@ -3,6 +3,9 @@
 namespace App\Console;
 
 use App\Console\Commands\Apollo;
+use App\Console\Commands\BehaviorRecord;
+use App\Console\Commands\CalcPostWeight;
+use App\Console\Commands\ContentFeedCreate;
 use Illuminate\Console\Scheduling\Schedule;
 use Laravel\Lumen\Console\Kernel as ConsoleKernel;
 
@@ -15,6 +18,9 @@ class Kernel extends ConsoleKernel
      */
     protected $commands = [
         Apollo::class,
+        BehaviorRecord::class,
+        CalcPostWeight::class,
+        ContentFeedCreate::class
     ];
 
     /**
@@ -26,6 +32,7 @@ class Kernel extends ConsoleKernel
     protected function schedule(Schedule $schedule)
     {
         $path = storage_path('logs/'.date('Y-m-d').'-schedule.log');
-
+        $schedule->command('post:calc_weight')
+            ->everyFifteenMinutes()->withoutOverlapping()->appendOutputTo($path);
     }
 }