mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 03:01:12 +00:00
feat: 添加Umeng日志模型及数据库迁移
This commit is contained in:
parent
0116d92021
commit
96106498d8
@ -258,6 +258,7 @@ class IndexController extends InvokeController
|
|||||||
Task::deliver(new DeleteTmpTask('file'));
|
Task::deliver(new DeleteTmpTask('file'));
|
||||||
Task::deliver(new DeleteTmpTask('tmp_file', 24));
|
Task::deliver(new DeleteTmpTask('tmp_file', 24));
|
||||||
Task::deliver(new DeleteTmpTask('user_device', 24));
|
Task::deliver(new DeleteTmpTask('user_device', 24));
|
||||||
|
Task::deliver(new DeleteTmpTask('umeng_log', 24 * 3));
|
||||||
// 删除机器人消息
|
// 删除机器人消息
|
||||||
Task::deliver(new DeleteBotMsgTask());
|
Task::deliver(new DeleteBotMsgTask());
|
||||||
// 周期任务
|
// 周期任务
|
||||||
|
|||||||
@ -70,6 +70,9 @@ class UmengAlias extends AbstractModel
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$instance = null;
|
||||||
|
$responsePayload = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch ($first['platform']) {
|
switch ($first['platform']) {
|
||||||
case 'ios':
|
case 'ios':
|
||||||
@ -81,8 +84,11 @@ class UmengAlias extends AbstractModel
|
|||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$instance->send($first['data']);
|
$responsePayload = $instance->send($first['data']);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
$responsePayload = [
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
];
|
||||||
$first['retry'] = intval($first['retry'] ?? 0) + 1;
|
$first['retry'] = intval($first['retry'] ?? 0) + 1;
|
||||||
if ($first['retry'] > 3) {
|
if ($first['retry'] > 3) {
|
||||||
info("[PushMsg] fail: " . $e->getMessage());
|
info("[PushMsg] fail: " . $e->getMessage());
|
||||||
@ -91,6 +97,12 @@ class UmengAlias extends AbstractModel
|
|||||||
self::$waitSend[] = $first;
|
self::$waitSend[] = $first;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
if ($instance !== null) {
|
||||||
|
UmengLog::create([
|
||||||
|
'request' => Base::array2json($first['data']),
|
||||||
|
'response' => Base::array2json($responsePayload),
|
||||||
|
]);
|
||||||
|
}
|
||||||
self::sendTask();
|
self::sendTask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
app/Models/UmengLog.php
Normal file
32
app/Models/UmengLog.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* App\Models\UmengLog
|
||||||
|
*
|
||||||
|
* @property int $id
|
||||||
|
* @property string|null $request 请求参数
|
||||||
|
* @property string|null $response 推送返回
|
||||||
|
* @property \Illuminate\Support\Carbon|null $created_at
|
||||||
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel cancelAppend()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel cancelHidden()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel change($array)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel getKeyValue()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel remove()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel saveOrIgnore()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog whereCreatedAt($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog whereId($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog whereRequest($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog whereResponse($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|UmengLog whereUpdatedAt($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class UmengLog extends AbstractModel
|
||||||
|
{
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@ -6,6 +6,7 @@ use App\Models\File;
|
|||||||
use App\Models\TaskWorker;
|
use App\Models\TaskWorker;
|
||||||
use App\Models\Tmp;
|
use App\Models\Tmp;
|
||||||
use App\Models\UserDevice;
|
use App\Models\UserDevice;
|
||||||
|
use App\Models\UmengLog;
|
||||||
use App\Models\WebSocketTmpMsg;
|
use App\Models\WebSocketTmpMsg;
|
||||||
use App\Module\Base;
|
use App\Module\Base;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
@ -103,6 +104,17 @@ class DeleteTmpTask extends AbstractTask
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'umeng_log':
|
||||||
|
UmengLog::where('created_at', '<', Carbon::now()->subHours($this->hours))
|
||||||
|
->orderBy('id')
|
||||||
|
->chunk(500, function ($logs) {
|
||||||
|
/** @var UmengLog $log */
|
||||||
|
foreach ($logs as $log) {
|
||||||
|
$log->delete();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('umeng_logs', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->text('request')->nullable()->comment('请求参数');
|
||||||
|
$table->text('response')->nullable()->comment('推送返回');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('umeng_logs');
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user