Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
engine
Commits
c9abd39f
Commit
c9abd39f
authored
4 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Remove stale timers. #41
parent
c713ad86
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/core/control.py
+33
-26
33 additions, 26 deletions
src/core/control.py
with
33 additions
and
26 deletions
src/core/control.py
+
33
−
26
View file @
c9abd39f
...
...
@@ -120,7 +120,7 @@ class SocketControlInterface:
"""
Starts the socket server
"""
while
(
True
):
while
True
:
try
:
self
.
server
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
server
.
bind
((
host
,
SocketControlInterface
.
PORT
))
...
...
@@ -133,10 +133,9 @@ class SocketControlInterface:
logger
.
info
(
SU
.
yellow
(
f
'
[ECI] Listening at
{
host
}
:
{
SocketControlInterface
.
PORT
}
'
))
self
.
server
.
listen
()
while
(
True
)
:
while
True
:
(
conn
,
client
)
=
self
.
server
.
accept
()
while
(
True
):
while
True
:
r
=
SocketReader
(
conn
)
p
=
HttpStream
(
r
)
data
=
p
.
body_file
().
read
()
...
...
@@ -226,6 +225,7 @@ class EngineExecutor(Timer):
self
.
dt
=
datetime
.
now
()
+
timedelta
(
seconds
=
diff
)
self
.
func
=
func
self
.
param
=
param
self
.
update_store
()
if
diff
<
0
:
msg
=
f
"
Timer
'
{
self
.
timer_id
}
'
is due in the past. Executing immediately ...
"
...
...
@@ -236,9 +236,7 @@ class EngineExecutor(Timer):
self
.
exec_now
()
else
:
self
.
exec_timed
()
self
.
start
()
self
.
update_store
()
self
.
start
()
def
wait_for_parent
(
self
):
...
...
@@ -246,9 +244,9 @@ class EngineExecutor(Timer):
Child timers are dependend on their parents. So let
'
s wait until parents are done with their stuff.
"""
if
self
.
parent_timer
and
self
.
parent_timer
.
is_alive
():
while
(
self
.
parent_timer
.
is_alive
()
)
:
while
self
.
parent_timer
.
is_alive
():
self
.
logger
.
info
(
f
"
Timer
'
{
self
.
timer_id
}
'
is waiting for parent timer
'
{
self
.
parent_timer
.
timer_id
}
'
to finish
"
)
time
.
sleep
(
0.
1
)
time
.
sleep
(
0.
2
)
def
exec_now
(
self
):
...
...
@@ -259,23 +257,16 @@ class EngineExecutor(Timer):
self
.
wait_for_parent
()
thread
=
Thread
(
target
=
self
.
func
,
args
=
(
self
.
param
,))
thread
.
start
()
def
exec_timed
(
self
):
"""
Timed execution in a thread.
"""
def
wrapper_func
(
param
=
None
):
self
.
wait_for_parent
()
# Remove from store
self
.
logger
.
info
(
SU
.
green
(
f
"
Removing old timer with ID:
{
self
.
timer_id
}
"
))
del
EngineExecutor
.
timer_store
[
self
.
timer_id
]
# Call actual function
self
.
wait_for_parent
()
if
param
:
self
.
func
(
param
,)
else
:
self
.
func
()
else
:
self
.
func
()
Timer
.
__init__
(
self
,
self
.
diff
,
wrapper_func
,
(
self
.
param
,))
...
...
@@ -287,13 +278,13 @@ class EngineExecutor(Timer):
if
self
.
timer_id
in
EngineExecutor
.
timer_store
:
existing_command
=
EngineExecutor
.
timer_store
[
self
.
timer_id
]
if
existing_command
:
self
.
logger
.
info
(
SU
.
green
(
f
"
Cancelling previous timer with ID:
{
self
.
timer_id
}
"
)
)
self
.
logger
.
debug
(
f
"
Cancelling previous timer with ID:
{
self
.
timer_id
}
"
)
existing_command
.
cancel
()
if
existing_command
.
child_timer
:
self
.
logger
.
info
(
SU
.
green
(
f
"
Cancelling child timer with ID:
{
existing_command
.
child_timer
.
timer_id
}
"
)
)
self
.
logger
.
debug
(
f
"
Cancelling child timer with ID:
{
existing_command
.
child_timer
.
timer_id
}
"
)
EngineExecutor
.
timer_store
[
self
.
timer_id
]
=
self
self
.
logger
.
info
(
SU
.
green
(
f
"
Created command timer with ID:
{
self
.
timer_id
}
"
)
)
self
.
logger
.
debug
(
f
"
Created command timer with ID:
{
self
.
timer_id
}
"
)
def
is_alive
(
self
):
...
...
@@ -312,13 +303,32 @@ class EngineExecutor(Timer):
return
f
"
[
{
self
.
timer_id
}
] exec at
{
str
(
self
.
dt
)
}
(alive:
{
self
.
is_alive
()
}
)
"
@staticmethod
def
remove_stale_timers
():
"""
Removes timers from store which have been executed and are older than one hour.
"""
timers
=
EngineExecutor
.
timer_store
.
values
()
del_keys
=
[]
for
timer
in
timers
:
if
timer
.
dt
<
datetime
.
now
()
-
timedelta
(
seconds
=
3600
):
if
not
timer
.
child_timer
or
(
timer
.
child_timer
and
not
timer
.
child_timer
.
is_alive
()):
timer
.
logger
.
debug
(
f
"
Removing already executed timer with ID:
{
timer
.
timer_id
}
"
)
del_keys
.
append
(
timer
.
timer_id
)
for
timer_id
in
del_keys
:
del
EngineExecutor
.
timer_store
[
timer_id
]
@staticmethod
def
log_commands
():
"""
Prints a list of active timers
to the log
.
Prints a list of active timers
and inactive timer not older than one hour
.
"""
timers
=
EngineExecutor
.
timer_store
.
values
()
msg
=
"
\n
[ ENGINE COMMAND QUEUE ]
\n
"
EngineExecutor
.
remove_stale_timers
()
if
not
timers
:
msg
+=
"
None available!
\n
"
...
...
@@ -330,6 +340,3 @@ class EngineExecutor(Timer):
msg
+=
f
"
=>
{
str
(
timer
.
child_timer
)
}
\n
"
EngineExecutor
.
logger
.
info
(
msg
+
"
\n
"
)
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