From a570beaf3e9c7851630f4db6bcf3406b37c6bdde Mon Sep 17 00:00:00 2001 From: Easy Date: Tue, 22 Mar 2022 14:31:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=9A=E6=9C=9F=E5=88=A0?= =?UTF-8?q?=E9=99=A4message=E7=9A=84=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/.env.example | 3 ++ api/app/Console/Commands/CleanOldPush.php | 50 +++++++++++++++++++ api/app/Console/Kernel.php | 3 +- ...022_03_22_042738_add_index_to_messages.php | 32 ++++++++++++ docker/web/Dockerfile | 3 ++ docker/web/larave-cron | 1 + 6 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 api/app/Console/Commands/CleanOldPush.php create mode 100644 api/database/migrations/2022_03_22_042738_add_index_to_messages.php create mode 100644 docker/web/larave-cron 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