Commit e7e8b184 authored by 刘小敏's avatar 刘小敏

定时任务脚本日志优化

parent 14b40d54
......@@ -7,7 +7,12 @@ use think\console\Output;
use think\Log;
use think\Db;
// 继承ThinkPHP命令行控制器基类,符合FastAdmin框架规范
/**
* 统计用户标签定时任务
* 每天凌晨两点执行
*
* 任务描述:每天凌晨两点执行,更新用户标签(活跃用户、高价值用户、沉默用户)
*/
class StatMemberTag extends Command
{
/**
......@@ -41,22 +46,22 @@ class StatMemberTag extends Command
$this->output->writeln($message);
custom_log($message, 'stat_member_tag', $level);
custom_log($message, 'stat', $level);
}
protected function execute(Input $input, Output $output) {
$this->output = $output;
$this->customLog('info', '========== 开始执行每日定时任务 ==========');
$this->customLog('info', '========== [' . date('Y-m-d H:i:s') . '] 开始执行统计用户标签定时任务 ==========');
try {
// 用户标签更新(带异常处理)
$this->updateUserTags();
$this->customLog('info', '[' . date('Y-m-d H:i:s') . ']每日定时任务执行完成');
$this->customLog('info', '========== [' . date('Y-m-d H:i:s') . '] 统计用户标签定时任务执行完成========== ');
} catch (\Exception $e) {
$this->customLog('error', '[' . date('Y-m-d H:i:s') . '] 任务执行失败: ' . $e->getMessage() . ' | 堆栈: ' . $e->getTraceAsString());
format_log_error_custom_name($e, '[' . date('Y-m-d H:i:s') . ']', '[任务执行失败]', 'stat');
}
}
......
......@@ -9,7 +9,10 @@ use think\Db;
use think\Queue;
/**
* 每日统计任务 PV UV
* 每日统计任务 PV UV 等指标
* 每天凌晨1点半执行
*
* 任务描述:每天凌晨1点半执行,统计昨日的PV UV 等指标
*/
class StatsDaily extends Command
{
......@@ -28,19 +31,23 @@ class StatsDaily extends Command
*/
protected function customLog($level, $message) {
$this->output->writeln($message);
// $this->output->writeln($message);
custom_log($message, 'stat_member_tag', $level);
custom_log($message, 'stat', $level);
}
protected function execute(Input $input, Output $output) {
$this->customLog('info', '========== [' . date('Y-m-d H:i:s') . '] 开始执行统计PVUV等指标任务 ==========');
// 清理过期数据
$this->cleanExpiredData();
// 统计数据汇总
$this->summaryStats();
$this->customLog('info', '========== [' . date('Y-m-d H:i:s') . '] 统计PVUV等指标任务执行完成========== ');
}
/**
......@@ -113,8 +120,7 @@ class StatsDaily extends Command
$this->customLog('info', '统计数据汇总完成,日期: ' . $date . ', UV: ' . $uv . ', PV: ' . $pv);
} catch (\Exception $e) {
$this->customLog('error', '统计数据汇总失败: ' . $e->getMessage());
// 统计失败不中断其他任务
format_log_error_custom_name($e, '[' . date('Y-m-d H:i:s') . ']' . '[统计数据汇总失败]', '', 'stat');
}
}
......
......@@ -9,7 +9,10 @@ use think\Db;
use think\Queue;
/**
* 重试失败的埋点数据 PV UV
* 重试失败的埋点数据 PV UV 等指标
* 每1个小时执行一次
*
* 任务描述:每1个小时执行一次,重试失败的埋点数据 PV UV 等指标
*/
class TrackFailedRetry extends Command
{
......@@ -29,13 +32,17 @@ class TrackFailedRetry extends Command
protected function customLog($level, $message) {
$this->output->writeln($message);
custom_log($message, 'stat_member_tag', $level);
custom_log($message, 'stat', $level);
}
protected function execute(Input $input, Output $output) {
$this->customLog('info', '========== [' . date('Y-m-d H:i:s') . '] 开始执行重试失败埋埋点数据任务 ==========');
$this->retryFailed();
$this->customLog('info', '========== [' . date('Y-m-d H:i:s') . '] 重试失败埋埋点数据任务执行完成========== ');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment