Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
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
tsai
CAP
Commits
8595d896
Commit
8595d896
authored
Jun 21, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename
parent
3c322c33
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
3 deletions
+85
-3
IProcessingServer.Job.cs
src/Cap.Consistency/Job/IProcessingServer.Job.cs
+82
-0
IProcessor.InfiniteRetry.cs
src/Cap.Consistency/Job/IProcessor.InfiniteRetry.cs
+3
-3
No files found.
src/Cap.Consistency/Job/IProcessingServer.Job.cs
0 → 100644
View file @
8595d896
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Cap.Consistency.Job
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.DependencyInjection
;
using
Cap.Consistency.Infrastructure
;
using
Microsoft.Extensions.Options
;
namespace
Cap.Consistency
{
public
class
JobProcessingServer
:
IProcessingServer
,
IDisposable
{
private
ILogger
_logger
;
private
ILoggerFactory
_loggerFactory
;
private
IServiceProvider
_provider
;
private
CancellationTokenSource
_cts
;
private
IJobProcessor
_processor
;
private
ConsistencyOptions
_options
;
private
ProcessingContext
_context
;
private
DefaultCronJobRegistry
_defaultJobRegistry
;
private
Task
_compositeTask
;
private
bool
_disposed
;
public
JobProcessingServer
(
ILogger
<
JobProcessingServer
>
logger
,
ILoggerFactory
loggerFactory
,
IServiceProvider
provider
,
DefaultCronJobRegistry
defaultJobRegistry
,
IOptions
<
ConsistencyOptions
>
options
)
{
_logger
=
logger
;
_loggerFactory
=
loggerFactory
;
_provider
=
provider
;
_defaultJobRegistry
=
defaultJobRegistry
;
_options
=
options
.
Value
;
_cts
=
new
CancellationTokenSource
();
}
public
void
Start
()
{
var
processorCount
=
Environment
.
ProcessorCount
;
_processor
=
_provider
.
GetService
<
IJobProcessor
>();
_logger
.
ServerStarting
(
processorCount
,
1
);
_context
=
new
ProcessingContext
(
_provider
,
_defaultJobRegistry
,
_cts
.
Token
);
_compositeTask
=
Task
.
Run
(()
=>
{
InfiniteRetry
(
_processor
).
ProcessAsync
(
_context
);
});
}
public
void
Dispose
()
{
if
(
_disposed
)
{
return
;
}
_disposed
=
true
;
_logger
.
ServerShuttingDown
();
_cts
.
Cancel
();
try
{
_compositeTask
.
Wait
((
int
)
TimeSpan
.
FromSeconds
(
60
).
TotalMilliseconds
);
}
catch
(
AggregateException
ex
)
{
var
innerEx
=
ex
.
InnerExceptions
[
0
];
if
(!(
innerEx
is
OperationCanceledException
))
{
_logger
.
ExpectedOperationCanceledException
(
innerEx
);
}
}
}
private
IJobProcessor
InfiniteRetry
(
IJobProcessor
inner
)
{
return
new
InfiniteRetryProcessor
(
inner
,
_loggerFactory
);
}
}
}
src/Cap.Consistency/Job/IProcessor.InfiniteRetry.cs
View file @
8595d896
...
@@ -6,13 +6,13 @@ using Microsoft.Extensions.Logging;
...
@@ -6,13 +6,13 @@ using Microsoft.Extensions.Logging;
namespace
Cap.Consistency.Job
namespace
Cap.Consistency.Job
{
{
public
class
InfiniteRetryProcessor
:
IProcessor
public
class
InfiniteRetryProcessor
:
I
Job
Processor
{
{
private
IProcessor
_inner
;
private
I
Job
Processor
_inner
;
private
ILogger
_logger
;
private
ILogger
_logger
;
public
InfiniteRetryProcessor
(
public
InfiniteRetryProcessor
(
IProcessor
inner
,
I
Job
Processor
inner
,
ILoggerFactory
loggerFactory
)
{
ILoggerFactory
loggerFactory
)
{
_inner
=
inner
;
_inner
=
inner
;
_logger
=
loggerFactory
.
CreateLogger
<
InfiniteRetryProcessor
>();
_logger
=
loggerFactory
.
CreateLogger
<
InfiniteRetryProcessor
>();
...
...
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