Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
quantum-blocks
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
ui
quantum-blocks
Commits
dddab3dc
Commit
dddab3dc
authored
Oct 28, 2022
by
徐光星
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 增加定时任务删除历史记录表半年前的数据
parent
ab0c0163
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
ClearInvalidPageHistory.ts
app/schedule/ClearInvalidPageHistory.ts
+20
-0
records.ts
app/service/records.ts
+18
-0
No files found.
app/schedule/ClearInvalidPageHistory.ts
0 → 100644
View file @
dddab3dc
import
{
Subscription
}
from
'
egg
'
;
class
clearInvalidPageHistoryRecords
extends
Subscription
{
// 通过 schedule 属性来设置定时任务的执行间隔等配置
static
get
schedule
()
{
return
{
cronOptions
:
{
tz
:
'
Asia/Shanghai
'
},
immediate
:
false
,
cron
:
'
0 0 2 L * *
'
,
// 每月的最后一天凌晨2点整执行
type
:
'
all
'
,
// 指定所有的 worker 都需要执行
};
}
async
subscribe
()
{
this
.
ctx
.
service
.
records
.
clearInvalidPageHistoryRecords
();
}
}
module
.
exports
=
clearInvalidPageHistoryRecords
;
\ No newline at end of file
app/service/records.ts
View file @
dddab3dc
...
@@ -6,4 +6,22 @@ export default class RecordsService extends Service {
...
@@ -6,4 +6,22 @@ export default class RecordsService extends Service {
super
(
ctx
);
super
(
ctx
);
this
.
context
=
ctx
;
this
.
context
=
ctx
;
}
}
async
clearInvalidPageHistoryRecords
()
{
// 操作记录表直接删除半年以上的操作记录
const
limitDate
=
new
Date
(
new
Date
().
getTime
()
-
180
*
24
*
3600
*
1000
).
toLocaleDateString
().
replace
(
/
\/
/g
,
'
-
'
)
try
{
this
.
context
.
logger
.
info
(
`开始删除页面历史记录,删除范围为日期在
${
limitDate
}
之前的所有记录`
);
await
this
.
context
.
model
.
PageHistory
.
destroy
({
where
:
{
updated_at
:
{
$lte
:
new
Date
(
limitDate
)
}
}
});
this
.
context
.
logger
.
info
(
`页面历史记录删除成功,删除范围为日期在
${
limitDate
}
之前的所有记录`
);
}
catch
(
err
)
{
this
.
context
.
logger
.
info
(
`页面历史记录删除失败,失败原因:
${
JSON
.
stringify
(
err
)}
`
);
}
return
;
}
}
}
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