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
08a32b60
Commit
08a32b60
authored
Nov 23, 2020
by
ruyun.zhang@suvalue.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
使用自定义后台任务处理程序
parent
50838fdc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
154 additions
and
55 deletions
+154
-55
performance/Performance.Api/Controllers/AllotController.cs
+29
-4
performance/Performance.Api/IBackgroundTaskQueue.cs
+91
-0
performance/Performance.Api/Startup.cs
+18
-15
performance/Performance.Api/wwwroot/Performance.Api.xml
+7
-7
performance/Performance.Api/wwwroot/Performance.DtoModels.xml
+4
-29
performance/Performance.Api/wwwroot/Performance.EntityModels.xml
+5
-0
No files found.
performance/Performance.Api/Controllers/AllotController.cs
View file @
08a32b60
...
...
@@ -4,6 +4,7 @@
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Http.Internal
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Logging
;
using
Performance.DtoModels
;
using
Performance.EntityModels
;
...
...
@@ -32,12 +33,19 @@ public class AllotController : Controller
private
ILogger
<
AllotController
>
_logger
;
private
ClaimService
_claim
;
private
readonly
LogManageService
logManageService
;
private
IBackgroundTaskQueue
_backgroundTaskQueue
;
private
IServiceScopeFactory
_serviceScopeFactory
;
public
AllotController
(
AllotService
allotService
,
ResultComputeService
resultComputeService
,
HospitalService
hospitalService
,
ConfigService
configService
,
ILogger
<
AllotController
>
logger
,
IHostingEnvironment
evn
,
ClaimService
claim
,
LogManageService
logManageService
)
HospitalService
hospitalService
,
ConfigService
configService
,
ILogger
<
AllotController
>
logger
,
IHostingEnvironment
evn
,
IBackgroundTaskQueue
backgroundTaskQueue
,
IServiceScopeFactory
serviceScopeFactory
,
ClaimService
claim
,
LogManageService
logManageService
)
{
_allotService
=
allotService
;
this
.
resultComputeService
=
resultComputeService
;
...
...
@@ -47,6 +55,8 @@ public class AllotController : Controller
_claim
=
claim
;
this
.
logManageService
=
logManageService
;
_configService
=
configService
;
_backgroundTaskQueue
=
backgroundTaskQueue
;
_serviceScopeFactory
=
serviceScopeFactory
;
}
/// <summary>
...
...
@@ -182,9 +192,24 @@ public ApiResponse Generate([CustomizeValidator(RuleSet = "Delete"), FromBody] A
logManageService
.
WriteMsg
(
"生成绩效准备中"
,
$"准备生成
{
allot
.
Year
}
-
{
allot
.
Month
.
ToString
().
PadLeft
(
2
,
'0'
)}
月份绩效,请稍等!"
,
1
,
allot
.
ID
,
"ReceiveMessage"
,
true
);
_allotService
.
UpdateAllotStates
(
allot
.
ID
,
(
int
)
AllotStates
.
Wait
,
EnumHelper
.
GetDescription
(
AllotStates
.
Wait
),
allot
.
Generate
);
if
(
_evn
.
IsEnvironment
(
"Localhost"
))
{
_allotService
.
Generate
(
allot
,
email
);
}
else
BackgroundJob
.
Schedule
(()
=>
_allotService
.
Generate
(
allot
,
email
),
TimeSpan
.
FromSeconds
(
1
));
{
//BackgroundJob.Schedule(() => _allotService.Generate(allot, email), TimeSpan.FromSeconds(1));
_backgroundTaskQueue
.
QueueBackgroundWorkItem
(
async
token
=>
{
using
(
var
scope
=
_serviceScopeFactory
.
CreateScope
())
{
var
scopedServices
=
scope
.
ServiceProvider
.
GetRequiredService
<
AllotService
>();
scopedServices
.
Generate
(
allot
,
email
);
await
Task
.
Delay
(
TimeSpan
.
FromSeconds
(
5
),
token
);
}
});
}
logManageService
.
WriteMsg
(
"等待绩效生成"
,
$"等待绩效生成
{
allot
.
Year
}
-
{
allot
.
Month
.
ToString
().
PadLeft
(
2
,
'0'
)}
月份绩效!"
,
1
,
allot
.
ID
,
"ReceiveMessage"
);
//_allotService.Generate(allot, email);
////BackgroundJob.Enqueue(() => _allotService.Generate(allot, email));
...
...
performance/Performance.Api/IBackgroundTaskQueue.cs
0 → 100644
View file @
08a32b60
using
System
;
using
System.Collections.Concurrent
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Logging
;
namespace
Performance.Api
{
public
interface
IBackgroundTaskQueue
{
void
QueueBackgroundWorkItem
(
Func
<
CancellationToken
,
Task
>
workItem
);
Task
<
Func
<
CancellationToken
,
Task
>>
DequeueAsync
(
CancellationToken
cancellationToken
);
}
public
class
BackgroundTaskQueue
:
IBackgroundTaskQueue
{
private
readonly
ConcurrentQueue
<
Func
<
CancellationToken
,
Task
>>
_workItems
=
new
ConcurrentQueue
<
Func
<
CancellationToken
,
Task
>>();
private
readonly
SemaphoreSlim
_signal
=
new
SemaphoreSlim
(
0
);
public
void
QueueBackgroundWorkItem
(
Func
<
CancellationToken
,
Task
>
workItem
)
{
if
(
workItem
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
workItem
));
}
_workItems
.
Enqueue
(
workItem
);
_signal
.
Release
();
}
public
async
Task
<
Func
<
CancellationToken
,
Task
>>
DequeueAsync
(
CancellationToken
cancellationToken
)
{
await
_signal
.
WaitAsync
(
cancellationToken
);
_workItems
.
TryDequeue
(
out
var
workItem
);
return
workItem
;
}
}
public
class
QueuedHostedService
:
BackgroundService
{
private
readonly
ILogger
<
QueuedHostedService
>
_logger
;
public
QueuedHostedService
(
IBackgroundTaskQueue
taskQueue
,
ILogger
<
QueuedHostedService
>
logger
)
{
TaskQueue
=
taskQueue
;
_logger
=
logger
;
}
public
IBackgroundTaskQueue
TaskQueue
{
get
;
}
protected
override
async
Task
ExecuteAsync
(
CancellationToken
stoppingToken
)
{
_logger
.
LogInformation
(
$"Queued Hosted Service is running.
{
Environment
.
NewLine
}
{
Environment
.
NewLine
}
Tap W to add a work item to the background queue.
{
Environment
.
NewLine
}
"
);
await
BackgroundProcessing
(
stoppingToken
);
}
private
async
Task
BackgroundProcessing
(
CancellationToken
stoppingToken
)
{
while
(!
stoppingToken
.
IsCancellationRequested
)
{
var
workItem
=
await
TaskQueue
.
DequeueAsync
(
stoppingToken
);
try
{
await
workItem
(
stoppingToken
);
}
catch
(
Exception
ex
)
{
_logger
.
LogError
(
ex
,
"Error occurred executing {WorkItem}."
,
nameof
(
workItem
));
}
}
}
public
override
async
Task
StopAsync
(
CancellationToken
stoppingToken
)
{
_logger
.
LogInformation
(
"Queued Hosted Service is stopping."
);
await
base
.
StopAsync
(
stoppingToken
);
}
}
}
\ No newline at end of file
performance/Performance.Api/Startup.cs
View file @
08a32b60
...
...
@@ -150,15 +150,18 @@ public void ConfigureServices(IServiceCollection services)
services
.
AddMemoryCache
();
#
region
hangfire
services
.
AddHangfire
(
config
=>
{
config
.
UseFilter
(
new
AutomaticRetryAttribute
{
Attempts
=
0
});
config
.
UseStorage
(
new
MySqlStorage
(
connection
.
Value
.
HangfireConnectionString
));
});
#
endregion
hangfire
services
.
AddHostedService
<
QueuedHostedService
>();
services
.
AddSingleton
<
IBackgroundTaskQueue
,
BackgroundTaskQueue
>();
// #region hangfire
//
// services.AddHangfire(config =>
// {
// config.UseFilter(new AutomaticRetryAttribute { Attempts = 0 });
// config.UseStorage(new MySqlStorage(connection.Value.HangfireConnectionString));
// });
//
// #endregion hangfire
services
.
AddSignalR
();
services
.
AddCors
(
options
=>
...
...
@@ -240,12 +243,12 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
#
endregion
Swagger
#
region
hangfire
app
.
UseHangfireServer
();
app
.
UseHangfireDashboard
(
"/hangfire"
,
new
DashboardOptions
{
Authorization
=
new
[]
{
new
HangfireAuthorizationFilter
()
}
});
#
endregion
hangfire
//
#region hangfire
//
//
app.UseHangfireServer();
//
app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new HangfireAuthorizationFilter() } });
//
//
#endregion hangfire
app
.
UseCors
(
"SignalrCore"
);
app
.
UseSignalR
(
routes
=>
routes
.
MapHub
<
AllotLogHub
>(
"/performance/allotLogHub"
));
...
...
performance/Performance.Api/wwwroot/Performance.Api.xml
View file @
08a32b60
...
...
@@ -22,13 +22,13 @@
</remarks>
<param
name=
"request"
></param>
<returns></returns>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.AccountController.Refresh"
>
<summary>
刷新登录JWT TOKEN
</summary>
<returns></returns>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.AccountController.SelfInfo"
>
<summary>
...
...
@@ -613,7 +613,7 @@
新增人员
</summary>
<param
name=
"request"
></param>
<returns></returns>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.EmployeeController.Update(Performance.DtoModels.EmployeeRequest)"
>
<summary>
...
...
@@ -641,7 +641,7 @@
新增临床人员
</summary>
<param
name=
"request"
></param>
<returns></returns>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.EmployeeController.UpdateClinic(Performance.EntityModels.im_employee_clinic)"
>
<summary>
...
...
@@ -669,7 +669,7 @@
新增临床人员
</summary>
<param
name=
"request"
></param>
<returns></returns>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.EmployeeController.UpdateLogistics(Performance.EntityModels.im_employee_logistics)"
>
<summary>
...
...
@@ -718,7 +718,7 @@
新增人员补充绩效
</summary>
<param
name=
"request"
></param>
<returns></returns>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.EmployeeController.UpdateApr(Performance.EntityModels.per_apr_amount)"
>
<summary>
...
...
@@ -1158,7 +1158,7 @@
<summary>
选择二次绩效模板
</summary>
<returns></returns>
<returns></returns>
</member>
<member
name=
"M:Performance.Api.Controllers.SecondAllotController.UseTemp(Performance.DtoModels.UseTempRequest)"
>
<summary>
...
...
performance/Performance.Api/wwwroot/Performance.DtoModels.xml
View file @
08a32b60
...
...
@@ -3284,24 +3284,14 @@
</member>
<member
name=
"P:Performance.DtoModels.SecondListResponse.States"
>
<summary>
0 数据未上传 1 数据已上传 2 正在校验数据 3 数据验证通过
4 数据错误 5 正在生成绩效 6 下发绩效 7 绩效解析失败
0 数据未上传 1 数据已上传 2 正在校验数据 3 数据验证通过
4 数据错误 5 正在生成绩效 6 下发绩效 7 绩效解析失败
8 归档 9 等待生成 10 绩效结果解析成功
</summary>
</member>
<member
name=
"P:Performance.DtoModels.Second
PerforResponse.EmployeeName
"
>
<member
name=
"P:Performance.DtoModels.Second
ListResponse.ShowFormula
"
>
<summary>
人员姓名
</summary>
</member>
<member
name=
"P:Performance.DtoModels.SecondPerforResponse.JobTitle"
>
<summary>
职务
</summary>
</member>
<member
name=
"P:Performance.DtoModels.SecondPerforResponse.JobNumber"
>
<summary>
人员工号
0 不显示 1 显示
</summary>
</member>
<member
name=
"P:Performance.DtoModels.SecondPerforResponse.Efficiency"
>
...
...
@@ -3324,21 +3314,6 @@
发放系数
</summary>
</member>
<member
name=
"P:Performance.DtoModels.SecondPerforResponse.ShouldGiveFee"
>
<summary>
应发管理绩效
</summary>
</member>
<member
name=
"P:Performance.DtoModels.SecondPerforResponse.PerforSumFee"
>
<summary>
绩效合计
</summary>
</member>
<member
name=
"P:Performance.DtoModels.SecondPerforResponse.ScoreAverageRate"
>
<summary>
考核对分率
</summary>
</member>
<member
name=
"P:Performance.DtoModels.HeadItem.IsBring"
>
<summary>
1 带出历史数据 2不带出
</summary>
</member>
...
...
performance/Performance.Api/wwwroot/Performance.EntityModels.xml
View file @
08a32b60
...
...
@@ -5438,6 +5438,11 @@
</summary>
</member>
<member
name=
"P:Performance.EntityModels.sys_role.IsViewAllUsers"
>
<summary>
是否查看所有用户 1 启用 2禁用
</summary>
</member>
<member
name=
"T:Performance.EntityModels.sys_role_menu"
>
<summary>
角色菜单关联表
...
...
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