@kne/fastify-task 2.0.7 → 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +16 -15
- package/libs/controllers/main.js +76 -1
- package/libs/controllers/statistics.js +9 -154
- package/libs/models/task.js +34 -3
- package/libs/services/main.js +203 -89
- package/libs/services/statistics.js +63 -966
- package/package.json +2 -3
- package/libs/models/task-daily-statistics.js +0 -66
- package/libs/models/task-hourly-statistics.js +0 -48
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kne/fastify-task",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
4
|
"description": "一个 Fastify 插件,用于任务编排、追踪任务执行状态和结果。支持系统自动执行和手动执行两种模式,提供完整的任务生命周期管理",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -56,8 +56,7 @@
|
|
|
56
56
|
"sqlite3": "^5.1.7"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@fastify
|
|
60
|
-
"dayjs": "^1.11.13",
|
|
59
|
+
"@kne/fastify-statistics": "^0.1.0-alpha.2",
|
|
61
60
|
"fastify-cron": "^1.4.0",
|
|
62
61
|
"fs-extra": "^11.3.0"
|
|
63
62
|
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
module.exports = ({ DataTypes, definePrimaryType, options }) => {
|
|
2
|
-
return {
|
|
3
|
-
model: {
|
|
4
|
-
date: {
|
|
5
|
-
type: DataTypes.DATEONLY,
|
|
6
|
-
comment: '统计日期(按完成日期)'
|
|
7
|
-
},
|
|
8
|
-
totalCompleted: {
|
|
9
|
-
type: DataTypes.INTEGER,
|
|
10
|
-
defaultValue: 0,
|
|
11
|
-
comment: '当天完成任务总数'
|
|
12
|
-
},
|
|
13
|
-
successCount: {
|
|
14
|
-
type: DataTypes.INTEGER,
|
|
15
|
-
defaultValue: 0,
|
|
16
|
-
comment: '成功数'
|
|
17
|
-
},
|
|
18
|
-
failedCount: {
|
|
19
|
-
type: DataTypes.INTEGER,
|
|
20
|
-
defaultValue: 0,
|
|
21
|
-
comment: '失败数'
|
|
22
|
-
},
|
|
23
|
-
canceledCount: {
|
|
24
|
-
type: DataTypes.INTEGER,
|
|
25
|
-
defaultValue: 0,
|
|
26
|
-
comment: '取消数'
|
|
27
|
-
},
|
|
28
|
-
totalWaitingTime: {
|
|
29
|
-
type: DataTypes.BIGINT,
|
|
30
|
-
defaultValue: 0,
|
|
31
|
-
comment: '总等待时间(毫秒)'
|
|
32
|
-
},
|
|
33
|
-
totalExecutionTime: {
|
|
34
|
-
type: DataTypes.BIGINT,
|
|
35
|
-
defaultValue: 0,
|
|
36
|
-
comment: '总执行时间(毫秒)'
|
|
37
|
-
},
|
|
38
|
-
totalTime: {
|
|
39
|
-
type: DataTypes.BIGINT,
|
|
40
|
-
defaultValue: 0,
|
|
41
|
-
comment: '总耗时(毫秒, completedAt-createdAt)'
|
|
42
|
-
},
|
|
43
|
-
timedTaskCount: {
|
|
44
|
-
type: DataTypes.INTEGER,
|
|
45
|
-
defaultValue: 0,
|
|
46
|
-
comment: '有耗时数据的任务数'
|
|
47
|
-
},
|
|
48
|
-
byType: {
|
|
49
|
-
type: DataTypes.JSON,
|
|
50
|
-
defaultValue: {},
|
|
51
|
-
comment: '按任务类型分组统计'
|
|
52
|
-
},
|
|
53
|
-
byRunnerType: {
|
|
54
|
-
type: DataTypes.JSON,
|
|
55
|
-
defaultValue: {},
|
|
56
|
-
comment: '按执行者类型分组统计'
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
options: {
|
|
60
|
-
comment: '任务每日统计',
|
|
61
|
-
indexes: [
|
|
62
|
-
{ fields: ['date'], unique: true }
|
|
63
|
-
]
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
module.exports = ({ DataTypes }) => {
|
|
2
|
-
return {
|
|
3
|
-
model: {
|
|
4
|
-
bucketStartUtc: {
|
|
5
|
-
type: DataTypes.DATE,
|
|
6
|
-
allowNull: false,
|
|
7
|
-
comment: 'UTC 整点桶起始时间(按任务完成时刻归入该小时,与客户端时区无关)'
|
|
8
|
-
},
|
|
9
|
-
type: {
|
|
10
|
-
type: DataTypes.STRING,
|
|
11
|
-
allowNull: false,
|
|
12
|
-
comment: '任务类型'
|
|
13
|
-
},
|
|
14
|
-
runnerType: {
|
|
15
|
-
type: DataTypes.STRING,
|
|
16
|
-
allowNull: false,
|
|
17
|
-
comment: '执行方式 manual / system'
|
|
18
|
-
},
|
|
19
|
-
totalCompleted: {
|
|
20
|
-
type: DataTypes.INTEGER,
|
|
21
|
-
defaultValue: 0,
|
|
22
|
-
comment: '该桶内完成任务数'
|
|
23
|
-
},
|
|
24
|
-
successCount: {
|
|
25
|
-
type: DataTypes.INTEGER,
|
|
26
|
-
defaultValue: 0,
|
|
27
|
-
comment: '成功数'
|
|
28
|
-
},
|
|
29
|
-
failedCount: {
|
|
30
|
-
type: DataTypes.INTEGER,
|
|
31
|
-
defaultValue: 0,
|
|
32
|
-
comment: '失败数'
|
|
33
|
-
},
|
|
34
|
-
canceledCount: {
|
|
35
|
-
type: DataTypes.INTEGER,
|
|
36
|
-
defaultValue: 0,
|
|
37
|
-
comment: '取消数'
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
options: {
|
|
41
|
-
comment: '任务按 UTC 小时 + 类型 + 执行方式的完成数预聚合(由定时任务从任务表重算,读接口按客户端时区换算展示)',
|
|
42
|
-
indexes: [
|
|
43
|
-
{ unique: true, fields: ['bucket_start_utc', 'type', 'runner_type'] },
|
|
44
|
-
{ fields: ['bucket_start_utc'] }
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
};
|