mirror of
https://github.com/easychen/pushdeer.git
synced 2025-02-23 00:14:56 +08:00
添加定期删除message的任务
This commit is contained in:
parent
967e1d4bcb
commit
a570beaf3e
@ -66,3 +66,6 @@ WECHAT_APPSECRET=
|
|||||||
|
|
||||||
MAX_PUSH_EVERY_USER_PER_MINUTE=60
|
MAX_PUSH_EVERY_USER_PER_MINUTE=60
|
||||||
MAX_PUSH_KEY_PER_TIME=100
|
MAX_PUSH_KEY_PER_TIME=100
|
||||||
|
|
||||||
|
# 清理N天前的推送消息,0为不清理
|
||||||
|
MAX_PUSH_EXISTS_DAYS=0
|
||||||
|
50
api/app/Console/Commands/CleanOldPush.php
Normal file
50
api/app/Console/Commands/CleanOldPush.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use App\Models\PushDeerMessage;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class CleanOldPush extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'app:cleanpush';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = '清除过时的推送内容';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$items_count = 10000; // 每次最多删除条数
|
||||||
|
$days = intval(env('MAX_PUSH_EXISTS_DAYS'));
|
||||||
|
if ($days > 0) {
|
||||||
|
// echo "进入清理模式";
|
||||||
|
PushDeerMessage::whereDate('created_at', '<', Carbon::now()->subDays($days))->take($items_count)->delete();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -15,7 +15,8 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
// $schedule->command('inspire')->hourly();
|
// $schedule->command('app:cleanpush')->everyMinute();
|
||||||
|
$schedule->command('app:cleanpush')->hourly();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddIndexToMessages extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('push_deer_messages', function (Blueprint $table) {
|
||||||
|
$table->index(['created_at'], 'created');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('push_deer_messages', function (Blueprint $table) {
|
||||||
|
$table->dropIndex('created');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -20,5 +20,8 @@ RUN chmod +x /data/gorush
|
|||||||
ADD supervisord-ios.conf /opt/docker/etc/supervisor.d/push-ios.conf
|
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 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
|
EXPOSE 80
|
||||||
|
|
||||||
|
1
docker/web/larave-cron
Normal file
1
docker/web/larave-cron
Normal file
@ -0,0 +1 @@
|
|||||||
|
* * * * * cd /app/api && php artisan schedule:run >> /dev/null 2>&1
|
Loading…
x
Reference in New Issue
Block a user