diff --git a/api/.env.example b/api/.env.example index 6be603d..a9a3956 100644 --- a/api/.env.example +++ b/api/.env.example @@ -66,3 +66,6 @@ WECHAT_APPSECRET= MAX_PUSH_EVERY_USER_PER_MINUTE=60 MAX_PUSH_KEY_PER_TIME=100 + +# 清理N天前的推送消息,0为不清理 +MAX_PUSH_EXISTS_DAYS=0 diff --git a/api/app/Console/Commands/CleanOldPush.php b/api/app/Console/Commands/CleanOldPush.php new file mode 100644 index 0000000..c3a9715 --- /dev/null +++ b/api/app/Console/Commands/CleanOldPush.php @@ -0,0 +1,50 @@ + 0) { + // echo "进入清理模式"; + PushDeerMessage::whereDate('created_at', '<', Carbon::now()->subDays($days))->take($items_count)->delete(); + } + return 0; + } +} diff --git a/api/app/Console/Kernel.php b/api/app/Console/Kernel.php index d8bc1d2..7ec990f 100644 --- a/api/app/Console/Kernel.php +++ b/api/app/Console/Kernel.php @@ -15,7 +15,8 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { - // $schedule->command('inspire')->hourly(); + // $schedule->command('app:cleanpush')->everyMinute(); + $schedule->command('app:cleanpush')->hourly(); } /** diff --git a/api/database/migrations/2022_03_22_042738_add_index_to_messages.php b/api/database/migrations/2022_03_22_042738_add_index_to_messages.php new file mode 100644 index 0000000..b0b3016 --- /dev/null +++ b/api/database/migrations/2022_03_22_042738_add_index_to_messages.php @@ -0,0 +1,32 @@ +index(['created_at'], 'created'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('push_deer_messages', function (Blueprint $table) { + $table->dropIndex('created'); + }); + } +} diff --git a/docker/web/Dockerfile b/docker/web/Dockerfile index f19a5c6..79498d5 100644 --- a/docker/web/Dockerfile +++ b/docker/web/Dockerfile @@ -20,5 +20,8 @@ RUN chmod +x /data/gorush ADD supervisord-ios.conf /opt/docker/etc/supervisor.d/push-ios.conf ADD supervisord-clip.conf /opt/docker/etc/supervisor.d/push-clip.conf +ADD larave-cron /etc/cron.d +RUN chmod +x /etc/cron.d/larave-cron + EXPOSE 80 diff --git a/docker/web/larave-cron b/docker/web/larave-cron new file mode 100644 index 0000000..2c47cb0 --- /dev/null +++ b/docker/web/larave-cron @@ -0,0 +1 @@ +* * * * * cd /app/api && php artisan schedule:run >> /dev/null 2>&1 \ No newline at end of file