Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loveisland
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘小敏
loveisland
Commits
e7e8b184
Commit
e7e8b184
authored
May 22, 2026
by
刘小敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
定时任务脚本日志优化
parent
14b40d54
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
12 deletions
+30
-12
StatMemberTag.php
application/command/StatMemberTag.php
+10
-5
StatsDaily.php
application/command/StatsDaily.php
+11
-5
TrackFailedRetry.php
application/command/TrackFailedRetry.php
+9
-2
No files found.
application/command/StatMemberTag.php
View file @
e7e8b184
...
...
@@ -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'
);
}
}
...
...
application/command/StatsDaily.php
View file @
e7e8b184
...
...
@@ -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'
);
}
}
...
...
application/command/TrackFailedRetry.php
View file @
e7e8b184
...
...
@@ -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'
)
.
'] 重试失败埋埋点数据任务执行完成========== '
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment