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
Jun 29, 2017
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
...
@@ -34,30 +34,31 @@ namespace Breeze.Api
Logs
.
FullNode
.
LogInformation
(
$"Api starting on url
{
this
.
fullNode
.
Settings
.
ApiUri
}
"
);
Logs
.
FullNode
.
LogInformation
(
$"Api starting on url
{
this
.
fullNode
.
Settings
.
ApiUri
}
"
);
Program
.
Initialize
(
this
.
fullNodeBuilder
.
Services
,
this
.
fullNode
);
Program
.
Initialize
(
this
.
fullNodeBuilder
.
Services
,
this
.
fullNode
);
this
.
TryStart
Heartbeat
();
this
.
TryStart
KeepaliveMonitor
();
}
}
/// <summary>
/// <summary>
/// A heartbeat monitor that when enabled will shutdown
/// A KeepaliveMonitor when enabled will shutdown the
/// the node if no external beat was made during the trashold
/// node if no one is calling the keepalive endpoint
/// during a certain trashold window
/// </summary>
/// </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
// shortened for redability
var
monitor
=
this
.
apiFeatureOptions
.
Heartbeat
Monitor
;
var
monitor
=
this
.
apiFeatureOptions
.
Keepalive
Monitor
;
// check the trashold to trigger a shutdown
// 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
();
this
.
fullNode
.
Stop
();
return
Task
.
CompletedTask
;
return
Task
.
CompletedTask
;
},
},
this
.
fullNode
.
GlobalCancellation
.
Cancellation
.
Token
,
this
.
fullNode
.
GlobalCancellation
.
Cancellation
.
Token
,
repeatEvery
:
this
.
apiFeatureOptions
.
HeartbeatMonitor
?.
Heartbeat
Interval
,
repeatEvery
:
this
.
apiFeatureOptions
.
KeepaliveMonitor
?.
Keepalive
Interval
,
startAfter
:
TimeSpans
.
Minute
);
startAfter
:
TimeSpans
.
Minute
);
}
}
}
}
...
@@ -65,11 +66,11 @@ namespace Breeze.Api
...
@@ -65,11 +66,11 @@ namespace Breeze.Api
public
class
ApiFeatureOptions
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
};
}
}
}
}
...
...
Breeze/src/Breeze.Api/Controllers/NodeController.cs
View file @
8cf0a91d
...
@@ -47,17 +47,17 @@ namespace Breeze.Api.Controllers
...
@@ -47,17 +47,17 @@ namespace Breeze.Api.Controllers
}
}
/// <summary>
/// <summary>
/// Set the
hearbeat
flag.
/// Set the
keepalive
flag.
/// </summary>
/// </summary>
/// <returns></returns>
/// <returns></returns>
[
HttpPost
]
[
HttpPost
]
[
Route
(
"
heartbeat
"
)]
[
Route
(
"
keepalive
"
)]
public
IActionResult
Heartbeat
()
public
IActionResult
Keepalive
()
{
{
if
(
this
.
apiFeatureOptions
.
Heartbeat
Monitor
==
null
)
if
(
this
.
apiFeatureOptions
.
Keepalive
Monitor
==
null
)
return
new
ObjectResult
(
"
Heartbeat
Disabled"
)
{
StatusCode
=
405
};
// (405) Method Not Allowed
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
();
return
this
.
Ok
();
}
}
...
...
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;
...
@@ -5,9 +5,9 @@ using System.Threading.Tasks;
namespace
Breeze.Api.Models
namespace
Breeze.Api.Models
{
{
public
class
Heartbeat
Monitor
public
class
Keepalive
Monitor
{
{
public
DateTime
LastBeat
{
get
;
set
;
}
public
DateTime
LastBeat
{
get
;
set
;
}
public
TimeSpan
Heartbeat
Interval
{
get
;
set
;
}
public
TimeSpan
Keepalive
Interval
{
get
;
set
;
}
}
}
}
}
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