Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
auto-tx
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vamp
auto-tx
Commits
5ed8b177
Commit
5ed8b177
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Use a list to keep track of suspend reasons
Refers to
#36
parent
0f9d7dd5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ATxService/AutoTx.cs
+18
-16
18 additions, 16 deletions
ATxService/AutoTx.cs
with
18 additions
and
16 deletions
ATxService/AutoTx.cs
+
18
−
16
View file @
5ed8b177
...
...
@@ -556,26 +556,26 @@ namespace ATxService
/// Check system parameters for valid ranges and update the global service state accordingly.
/// </summary>
private
void
UpdateServiceState
()
{
var
limit
Reason
=
""
;
var
suspend
Reason
s
=
new
List
<
string
>()
;
// check all system parameters for valid ranges and remember the reason in a string
// if one of them is failing (to report in the log why we're suspended)
if
(
_cpu
.
HighLoad
)
limitReason
=
"CPU usage"
;
else
if
(
SystemChecks
.
GetFreeMemory
()
<
_config
.
MinAvailableMemory
)
limitReason
=
"RAM usage"
;
else
{
var
blacklistedProcess
=
SystemChecks
.
CheckForBlacklistedProcesses
(
_config
.
BlacklistedProcesses
);
if
(
b
lacklistedProcess
!=
""
)
{
limitReason
=
"blacklisted process '"
+
blacklistedProcess
+
"'"
;
}
suspendReasons
.
Add
(
"CPU"
)
;
if
(
SystemChecks
.
GetFreeMemory
()
<
_config
.
MinAvailableMemory
)
suspendReasons
.
Add
(
"RAM"
);
var
blacklistedProcess
=
SystemChecks
.
CheckFor
BlacklistedProcesses
(
_config
.
B
lacklistedProcess
es
);
if
(!
string
.
IsNullOrWhiteSpace
(
blacklistedProcess
))
{
suspendReasons
.
Add
(
"process '"
+
blacklistedProcess
+
"'"
);
}
// all parameters within valid ranges, so set the state to "Running":
if
(
s
tring
.
IsNullOrEmpty
(
limitReason
)
)
{
_status
.
ServiceSuspended
=
false
;
if
(!
string
.
IsNullOrEmpty
(
_status
.
LimitReason
))
{
if
(
s
uspendReasons
.
Count
==
0
)
{
if
(
_status
.
ServiceSuspended
)
{
_status
.
ServiceSuspended
=
false
;
_status
.
LimitReason
=
""
;
// reset to force a message on next service suspend
Log
.
Info
(
"Service resuming operation (all parameters in valid ranges)."
);
}
...
...
@@ -584,8 +584,8 @@ namespace ATxService
// set state to "Running" if no-one is logged on:
if
(
SystemChecks
.
NoUserIsLoggedOn
())
{
_status
.
ServiceSuspended
=
false
;
if
(!
string
.
IsNullOrEmpty
(
_status
.
LimitReason
))
{
if
(
_status
.
ServiceSuspended
)
{
_status
.
ServiceSuspended
=
false
;
_status
.
LimitReason
=
""
;
// reset to force a message on next service suspend
Log
.
Info
(
"Service resuming operation (no user logged on)."
);
}
...
...
@@ -594,9 +594,11 @@ namespace ATxService
// by reaching this point we know the service should be suspended:
_status
.
ServiceSuspended
=
true
;
var
limitReason
=
string
.
Join
(
", "
,
suspendReasons
);
if
(
limitReason
==
_status
.
LimitReason
)
return
;
Log
.
Info
(
"Service suspended due to limitiations [{0}]."
,
limitReason
);
Log
.
Info
(
"Service suspended. Reason(s): [{0}]"
,
limitReason
);
_status
.
LimitReason
=
limitReason
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment