Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
performance
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zry
performance
Commits
8696386c
Commit
8696386c
authored
Feb 11, 2022
by
ruyun.zhang@suvalue.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化调整
parent
074ef3c1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
33 deletions
+63
-33
performance/Performance.Api/Controllers/AllotController.cs
+1
-1
performance/Performance.Api/Job/BackgroundJob.cs
+44
-28
performance/Performance.Api/wwwroot/Performance.Api.xml
+14
-0
performance/Performance.DtoModels/Enum.cs
+1
-1
performance/Performance.EntityModels/Entity/bg_task.cs
+1
-1
performance/Performance.Services/TaskService.cs
+2
-2
No files found.
performance/Performance.Api/Controllers/AllotController.cs
View file @
8696386c
...
...
@@ -328,7 +328,7 @@ public ApiResponse GenerateReport([CustomizeValidator(RuleSet = "Delete"), FromB
// await Task.Delay(TimeSpan.FromSeconds(5), token);
// }
//});
_taskService
.
Add
(
Background
.
JobType
.
生成
报表
,
allot
.
ID
.
ToString
());
_taskService
.
Add
(
Background
.
JobType
.
报表
,
allot
.
ID
.
ToString
());
return
new
ApiResponse
(
ResponseType
.
OK
,
"统计报表数据任务开始"
);
}
...
...
performance/Performance.Api/Job/BackgroundJob.cs
View file @
8696386c
...
...
@@ -33,7 +33,7 @@ public class BackgroundJob : IJob
{
new
BackgroundSetting
{
JobType
=
Background
.
JobType
.
提取数据
,
MaxThread
=
1
,
Timeout
=
90
},
new
BackgroundSetting
{
JobType
=
Background
.
JobType
.
生成测算表
,
MaxThread
=
2
,
Timeout
=
20
},
new
BackgroundSetting
{
JobType
=
Background
.
JobType
.
生成报表
,
MaxThread
=
1
,
Timeout
=
20
},
new
BackgroundSetting
{
JobType
=
Background
.
JobType
.
报表
,
MaxThread
=
5
,
Timeout
=
20
},
new
BackgroundSetting
{
JobType
=
Background
.
JobType
.
自定义抽取
,
MaxThread
=
1
,
Timeout
=
90
},
};
}
...
...
@@ -49,20 +49,35 @@ public void Execute()
if
(
tasks
==
null
||
tasks
.
Count
==
0
)
return
;
tasks
=
tasks
.
OrderBy
(
w
=>
w
.
ID
).
ToList
();
Timeout
(
service
,
tasks
);
Repeat
(
service
,
tasks
);
foreach
(
var
item
in
EnumHelper
.
GetItems
<
Background
.
JobType
>().
Select
(
w
=>
w
.
Value
))
foreach
(
var
jobType
in
EnumHelper
.
GetItems
<
Background
.
JobType
>().
Select
(
w
=>
w
.
Value
))
{
var
sett
=
_settings
.
FirstOrDefault
(
w
=>
(
int
)
w
.
JobType
==
item
);
if
(
sett
!=
null
)
var
sett
=
_settings
.
FirstOrDefault
(
w
=>
(
int
)
w
.
JobType
==
jobType
);
if
(
sett
!=
null
&&
tasks
.
Count
(
w
=>
w
.
JobType
==
jobType
&&
(
int
)
Background
.
Status
.
执行中
==
w
.
Status
)
>=
sett
.
MaxThread
)
{
if
(
tasks
.
Count
(
w
=>
w
.
JobType
==
item
&&
(
int
)
Background
.
Status
.
执行中
==
w
.
Status
)
>=
sett
.
MaxThread
)
continue
;
continue
;
}
var
task
=
tasks
.
OrderBy
(
w
=>
w
.
ID
).
FirstOrDefault
(
w
=>
w
.
JobType
==
item
&&
w
.
Status
==
(
int
)
Background
.
Status
.
等待
);
if
(
task
==
null
)
continue
;
#
region
相同参数同时只允许一个执行
bg_task
task
=
null
;
foreach
(
var
item
in
tasks
.
Where
(
w
=>
w
.
JobType
==
jobType
&&
w
.
Status
==
(
int
)
Background
.
Status
.
等待
))
{
if
(!
tasks
.
Any
(
w
=>
w
.
JobType
==
jobType
&&
(
int
)
Background
.
Status
.
执行中
==
w
.
Status
&&
w
.
Argument
==
item
.
Argument
))
{
task
=
item
;
break
;
}
}
if
(
task
==
null
)
{
continue
;
}
#
endregion
switch
(
task
.
JobType
)
{
...
...
@@ -72,7 +87,7 @@ public void Execute()
case
(
int
)
Background
.
JobType
.
提取数据
:
Execute_Allot_ExtractData
(
service
,
task
);
break
;
case
(
int
)
Background
.
JobType
.
生成
报表
:
case
(
int
)
Background
.
JobType
.
报表
:
Execute_Allot_Generate_Report
(
service
,
task
);
break
;
case
(
int
)
Background
.
JobType
.
自定义抽取
:
...
...
@@ -96,31 +111,32 @@ private void Execute_Allot_Generate(TaskService service, bg_task task)
using
(
var
scope
=
_serviceScopeFactory
.
CreateScope
())
{
var
allotService
=
scope
.
ServiceProvider
.
GetService
<
AllotService
>();
try
if
(
int
.
TryParse
(
task
.
Argument
,
out
int
allotId
))
{
if
(
int
.
TryParse
(
task
.
Argument
,
out
int
allotId
))
var
allot
=
allotService
.
GetAllot
(
allotId
);
if
(
allot
==
null
)
{
service
.
Update
(
task
.
ID
,
Background
.
Status
.
无效
);
return
;
}
try
{
var
allot
=
allotService
.
GetAllot
(
allotId
);
if
(
allot
==
null
)
{
service
.
Update
(
task
.
ID
,
Background
.
Status
.
无效
);
return
;
}
service
.
Update
(
task
.
ID
,
Background
.
Status
.
执行中
);
Stopwatch
stopwatch
=
Stopwatch
.
StartNew
();
allotService
.
Generate
(
allot
);
allotService
.
GenerateReport
(
allot
);
stopwatch
.
Stop
();
service
.
Update
(
task
.
ID
,
Background
.
Status
.
完成
,
milliseconds
:
stopwatch
.
ElapsedMillis
econds
);
service
.
Update
(
task
.
ID
,
Background
.
Status
.
完成
,
seconds
:
stopwatch
.
Elapsed
.
TotalS
econds
);
}
catch
(
Exception
ex
)
{
service
.
Update
(
task
.
ID
,
Background
.
Status
.
失败
,
ex
.
ToString
());
}
allotService
.
GenerateReport
(
allot
);
}
catch
(
Exception
ex
)
{
service
.
Update
(
task
.
ID
,
Background
.
Status
.
失败
,
ex
.
ToString
());
}
}
}
/// <summary>
...
...
@@ -151,7 +167,7 @@ private void Execute_Allot_Generate_Report(TaskService service, bg_task task)
allotService
.
GenerateReport
(
allot
);
stopwatch
.
Stop
();
service
.
Update
(
task
.
ID
,
Background
.
Status
.
完成
,
milliseconds
:
stopwatch
.
ElapsedMillis
econds
);
service
.
Update
(
task
.
ID
,
Background
.
Status
.
完成
,
seconds
:
stopwatch
.
Elapsed
.
TotalS
econds
);
}
}
catch
(
Exception
ex
)
...
...
@@ -205,7 +221,7 @@ private void Execute_Allot_CustomExtract(TaskService service, bg_task task)
stopwatch
.
Stop
();
service
.
Update
(
task
.
ID
,
Background
.
Status
.
完成
,
milliseconds
:
stopwatch
.
ElapsedMillis
econds
);
service
.
Update
(
task
.
ID
,
Background
.
Status
.
完成
,
seconds
:
stopwatch
.
Elapsed
.
TotalS
econds
);
}
}
...
...
@@ -289,7 +305,7 @@ private void Execute_Allot_ExtractData(TaskService service, bg_task task)
stopwatch
.
Stop
();
service
.
Update
(
task
.
ID
,
Background
.
Status
.
完成
,
milliseconds
:
stopwatch
.
ElapsedMillis
econds
);
service
.
Update
(
task
.
ID
,
Background
.
Status
.
完成
,
seconds
:
stopwatch
.
Elapsed
.
TotalS
econds
);
}
}
catch
(
Exception
ex
)
...
...
performance/Performance.Api/wwwroot/Performance.Api.xml
View file @
8696386c
...
...
@@ -2172,6 +2172,20 @@
<param
name=
"service"
></param>
<param
name=
"task"
></param>
</member>
<member
name=
"M:Performance.Api.BackgroundJob.Execute_Allot_Generate_Report(Performance.Services.TaskService,Performance.EntityModels.bg_task)"
>
<summary>
生成报表
</summary>
<param
name=
"service"
></param>
<param
name=
"task"
></param>
</member>
<member
name=
"M:Performance.Api.BackgroundJob.Execute_Allot_CustomExtract(Performance.Services.TaskService,Performance.EntityModels.bg_task)"
>
<summary>
提取绩效数据
</summary>
<param
name=
"service"
></param>
<param
name=
"task"
></param>
</member>
<member
name=
"M:Performance.Api.BackgroundJob.Timeout(Performance.Services.TaskService,System.Collections.Generic.List{Performance.EntityModels.bg_task})"
>
<summary>
超时关闭
...
...
performance/Performance.DtoModels/Enum.cs
View file @
8696386c
...
...
@@ -142,7 +142,7 @@ public enum JobType
{
生成测算表
=
1
,
提取数据
=
2
,
生成
报表
=
3
,
报表
=
3
,
自定义抽取
=
4
,
}
public
enum
Status
...
...
performance/Performance.EntityModels/Entity/bg_task.cs
View file @
8696386c
...
...
@@ -28,6 +28,6 @@ public class bg_task
public
int
Status
{
get
;
set
;
}
public
string
Argument
{
get
;
set
;
}
public
string
Remark
{
get
;
set
;
}
public
long
ElapsedTime
{
get
;
set
;
}
public
double
ElapsedTime
{
get
;
set
;
}
}
}
performance/Performance.Services/TaskService.cs
View file @
8696386c
...
...
@@ -40,7 +40,7 @@ public bool Add(Background.JobType type, string argument = "")
});
}
public
bool
Update
(
int
taskId
,
Background
.
Status
status
,
string
remark
=
""
,
long
milli
seconds
=
0
)
public
bool
Update
(
int
taskId
,
Background
.
Status
status
,
string
remark
=
""
,
double
seconds
=
0
)
{
var
task
=
_taskRepository
.
GetEntity
(
w
=>
w
.
ID
==
taskId
);
if
(
task
==
null
)
return
false
;
...
...
@@ -48,7 +48,7 @@ public bool Update(int taskId, Background.Status status, string remark = "", lon
task
.
Status
=
(
int
)
status
;
if
(
status
==
Background
.
Status
.
执行中
)
task
.
BeginTime
=
DateTime
.
Now
;
task
.
ElapsedTime
=
milliseconds
/
1000
;
task
.
ElapsedTime
=
seconds
;
task
.
Remark
=
$"
{(
Background
.
JobType
)
task
.
JobType
}
-
{
status
}
{
remark
}
"
;
if
(
status
==
Background
.
Status
.
完成
||
status
==
Background
.
Status
.
失败
||
status
==
Background
.
Status
.
超时
)
task
.
EndTime
=
DateTime
.
Now
;
...
...
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