haozi преди 5 години
родител
ревизия
1cebaed9f0
променени са 4 файла, в които са добавени 64 реда и са изтрити 16 реда
  1. 55 0
      LogExpireDelete.php
  2. 3 7
      app/Console/Commands/LogExpireDelete.php
  3. 3 5
      app/Console/Kernel.php
  4. 3 4
      runServes.sh

+ 55 - 0
LogExpireDelete.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Carbon\Carbon;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Date;
+use Illuminate\Support\Facades\DB;
+
+class LogExpireDelete extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'LogExpireDelete';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'LogExpireDelete';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->deleteLog();
+    }
+
+    public function deleteLog(){
+        //前一天
+//        $date=Carbon::now()->subDays(150)->format('Y-m-d');
+//        DB::table('logs')->where('created_at','like',$date.'%')->delete();
+        DB::table('logs')->insert([
+            ['operation' => 'App', 'type' => 'test','created_at'=>new Date()],
+        ]);
+
+    }
+}

+ 3 - 7
app/Console/Commands/LogExpireDelete.php

@@ -44,12 +44,8 @@ class LogExpireDelete extends Command
     }
 
     public function deleteLog(){
-        //前一天
-//        $date=Carbon::now()->subDays(150)->format('Y-m-d');
-//        DB::table('logs')->where('created_at','like',$date.'%')->delete();
-        DB::table('logs')->insert([
-            ['operation' => 'App', 'type' => 'test','created_at'=>new Date()],
-        ]);
-
+        //前150天
+        $date=Carbon::now()->subDays(150)->format('Y-m-d');
+        DB::table('logs')->where('created_at','like',$date.'%')->delete();
     }
 }

+ 3 - 5
app/Console/Kernel.php

@@ -2,6 +2,7 @@
 
 namespace App\Console;
 
+use Carbon\Carbon;
 use Illuminate\Console\Scheduling\Schedule;
 use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
 use Illuminate\Support\Facades\DB;
@@ -25,10 +26,8 @@ class Kernel extends ConsoleKernel
      */
     protected function schedule(Schedule $schedule)
     {
-        // $schedule->command('inspire')
-        //          ->hourly();
-        //$schedule->command('LogExpireDelete')->daily();
-        $schedule->command('LogExpireDelete')->everyMinute();
+        $schedule->command('LogExpireDelete')->daily();
+//        $schedule->command('LogExpireDelete')->everyMinute();
     }
 
     /**
@@ -39,7 +38,6 @@ class Kernel extends ConsoleKernel
     protected function commands()
     {
         $this->load(__DIR__.'/Commands');
-
         require base_path('routes/console.php');
     }
 }

+ 3 - 4
runServes.sh

@@ -12,9 +12,8 @@ nohup php artisan queue:work --tries=2 --delay=2 >/dev/null 2>&1 &
 
 
 
-
-isExistStr=$(cat /etc/crontab|grep '* * * * * /usr/bin/php /var/www_test/was/artisan schedule:run >> /dev/null 2>&1')
+isExistStr=$(cat /etc/crontab|grep '* * * * * root cd /var/www_test/was && php artisan schedule:run >> /dev/null 2>&1')
 if [ ! -n "$isExistStr" ]; then
-echo -e '\n* * * * * /usr/bin/php /var/www_test/was/artisan schedule:run >> /dev/null 2>&1' >> /etc/crontab
+echo -e '\n* * * * * root cd /var/www_test/was && php artisan schedule:run >> /dev/null 2>&1' >> /etc/crontab
 fi
-systemctl cron restart
+systemctl restart crond