Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Breeze
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DeStream-public
Breeze
Commits
8cf0a91d
Commit
8cf0a91d
authored
7 years ago
by
Dan Gershony
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename to keepalive
parent
d8d9e40e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
20 deletions
+21
-20
ApiFeature.cs
Breeze/src/Breeze.Api/ApiFeature.cs
+13
-12
NodeController.cs
Breeze/src/Breeze.Api/Controllers/NodeController.cs
+6
-6
KeepaliveMonitor.cs
Breeze/src/Breeze.Api/Models/KeepaliveMonitor.cs
+2
-2
No files found.
Breeze/src/Breeze.Api/ApiFeature.cs
View file @
8cf0a91d
...
...
@@ -34,30 +34,31 @@ namespace Breeze.Api
Logs
.
FullNode
.
LogInformation
(
$"Api starting on url
{
this
.
fullNode
.
Settings
.
ApiUri
}
"
);
Program
.
Initialize
(
this
.
fullNodeBuilder
.
Services
,
this
.
fullNode
);
this
.
TryStart
Heartbeat
();
this
.
TryStart
KeepaliveMonitor
();
}
/// <summary>
/// A heartbeat monitor that when enabled will shutdown
/// the node if no external beat was made during the trashold
/// A KeepaliveMonitor when enabled will shutdown the
/// node if no one is calling the keepalive endpoint
/// during a certain trashold window
/// </summary>
public
void
TryStart
Heartbeat
()
public
void
TryStart
KeepaliveMonitor
()
{
if
(
this
.
apiFeatureOptions
.
HeartbeatMonitor
?.
Heartbeat
Interval
.
TotalSeconds
>
0
)
if
(
this
.
apiFeatureOptions
.
KeepaliveMonitor
?.
Keepalive
Interval
.
TotalSeconds
>
0
)
{
this
.
asyncLoopFactory
.
Run
(
"ApiFeature.
MonitorHeartbeat
"
,
token
=>
this
.
asyncLoopFactory
.
Run
(
"ApiFeature.
KeepaliveMonitor
"
,
token
=>
{
// shortened for redability
var
monitor
=
this
.
apiFeatureOptions
.
Heartbeat
Monitor
;
var
monitor
=
this
.
apiFeatureOptions
.
Keepalive
Monitor
;
// check the trashold to trigger a shutdown
if
(
monitor
.
LastBeat
.
Add
(
monitor
.
Heartbeat
Interval
)
<
DateTime
.
UtcNow
)
if
(
monitor
.
LastBeat
.
Add
(
monitor
.
Keepalive
Interval
)
<
DateTime
.
UtcNow
)
this
.
fullNode
.
Stop
();
return
Task
.
CompletedTask
;
},
this
.
fullNode
.
GlobalCancellation
.
Cancellation
.
Token
,
repeatEvery
:
this
.
apiFeatureOptions
.
HeartbeatMonitor
?.
Heartbeat
Interval
,
repeatEvery
:
this
.
apiFeatureOptions
.
KeepaliveMonitor
?.
Keepalive
Interval
,
startAfter
:
TimeSpans
.
Minute
);
}
}
...
...
@@ -65,11 +66,11 @@ namespace Breeze.Api
public
class
ApiFeatureOptions
{
public
HeartbeatMonitor
Heartbeat
Monitor
{
get
;
set
;
}
public
KeepaliveMonitor
Keepalive
Monitor
{
get
;
set
;
}
public
void
Heartbeat
(
TimeSpan
timeSpan
)
public
void
Keepalive
(
TimeSpan
timeSpan
)
{
this
.
HeartbeatMonitor
=
new
HeartbeatMonitor
{
Heartbeat
Interval
=
timeSpan
};
this
.
KeepaliveMonitor
=
new
KeepaliveMonitor
{
Keepalive
Interval
=
timeSpan
};
}
}
...
...
This diff is collapsed.
Click to expand it.
Breeze/src/Breeze.Api/Controllers/NodeController.cs
View file @
8cf0a91d
...
...
@@ -47,17 +47,17 @@ namespace Breeze.Api.Controllers
}
/// <summary>
/// Set the
hearbeat
flag.
/// Set the
keepalive
flag.
/// </summary>
/// <returns></returns>
[
HttpPost
]
[
Route
(
"
heartbeat
"
)]
public
IActionResult
Heartbeat
()
[
Route
(
"
keepalive
"
)]
public
IActionResult
Keepalive
()
{
if
(
this
.
apiFeatureOptions
.
Heartbeat
Monitor
==
null
)
return
new
ObjectResult
(
"
Heartbeat
Disabled"
)
{
StatusCode
=
405
};
// (405) Method Not Allowed
if
(
this
.
apiFeatureOptions
.
Keepalive
Monitor
==
null
)
return
new
ObjectResult
(
"
Keepalive
Disabled"
)
{
StatusCode
=
405
};
// (405) Method Not Allowed
this
.
apiFeatureOptions
.
Heartbeat
Monitor
.
LastBeat
=
DateTime
.
UtcNow
;
this
.
apiFeatureOptions
.
Keepalive
Monitor
.
LastBeat
=
DateTime
.
UtcNow
;
return
this
.
Ok
();
}
...
...
This diff is collapsed.
Click to expand it.
Breeze/src/Breeze.Api/Models/
HearBeat
Monitor.cs
→
Breeze/src/Breeze.Api/Models/
Keepalive
Monitor.cs
View file @
8cf0a91d
...
...
@@ -5,9 +5,9 @@ using System.Threading.Tasks;
namespace
Breeze.Api.Models
{
public
class
Heartbeat
Monitor
public
class
Keepalive
Monitor
{
public
DateTime
LastBeat
{
get
;
set
;
}
public
TimeSpan
Heartbeat
Interval
{
get
;
set
;
}
public
TimeSpan
Keepalive
Interval
{
get
;
set
;
}
}
}
This diff is collapsed.
Click to expand it.
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