Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
agkyra
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
itminedu
agkyra
Commits
34b68269
Commit
34b68269
authored
9 years ago
by
Giorgos Korfiatis
Browse files
Options
Downloads
Patches
Plain Diff
improve syncer and daemon shutdown
parent
b3040f79
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
agkyra/protocol.py
+10
-46
10 additions, 46 deletions
agkyra/protocol.py
with
10 additions
and
46 deletions
agkyra/protocol.py
+
10
−
46
View file @
34b68269
...
...
@@ -182,38 +182,24 @@ class SessionHelper(object):
if
'
locked
'
not
in
'
%s
'
%
oe
:
raise
db
.
close
()
self
.
close_manager
()
self
.
server
.
shutdown
()
def
close_manager
(
self
):
manager
=
self
.
server
.
manager
manager
.
close_all
()
manager
.
stop
()
manager
.
join
()
def
start
(
self
):
"""
Start the helper server in a thread
"""
if
getattr
(
self
,
'
server
'
,
None
):
t
=
Thread
(
target
=
self
.
_shutdown_daemon
)
t
=
Thread
(
target
=
self
.
heartbeat
)
t
.
start
()
Thread
(
target
=
self
.
heartbeat
).
start
()
self
.
server
.
serve_forever
()
t
.
join
()
LOG
.
debug
(
'
WSGI server is down
'
)
def
_shutdown_daemon
(
self
):
"""
Shutdown WSGI server when the heart stops
"""
db
=
sqlite3
.
connect
(
self
.
session_db
)
while
True
:
time
.
sleep
(
4
)
try
:
r
=
db
.
execute
(
'
SELECT ui_id FROM %s WHERE ui_id=
"
%s
"'
%
(
self
.
session_relation
,
self
.
ui_id
))
if
not
r
.
fetchall
():
db
.
close
()
time
.
sleep
(
5
)
t
=
Thread
(
target
=
self
.
server
.
shutdown
)
t
.
start
()
t
.
join
()
break
except
sqlite3
.
OperationalError
:
pass
class
WebSocketProtocol
(
WebSocket
):
"""
Helper-side WebSocket protocol for communication with GUI:
...
...
@@ -341,28 +327,6 @@ class WebSocketProtocol(WebSocket):
LOG
.
debug
(
'
Wait open syncs to complete
'
)
syncer
.
wait_sync_threads
()
def
heartbeat
(
self
):
"""
Update session DB timestamp as long as session is alive
"""
db
,
alive
=
sqlite3
.
connect
(
self
.
session_db
),
True
while
alive
:
time
.
sleep
(
1
)
try
:
db
.
execute
(
'
BEGIN
'
)
r
=
db
.
execute
(
'
SELECT ui_id FROM %s WHERE ui_id=
"
%s
"'
%
(
self
.
session_relation
,
self
.
ui_id
))
if
r
.
fetchall
():
db
.
execute
(
'
UPDATE %s SET beat=
"
%s
"
WHERE ui_id=
"
%s
"'
%
(
self
.
session_relation
,
time
.
time
(),
self
.
ui_id
))
else
:
alive
=
False
db
.
commit
()
except
sqlite3
.
OperationalError
:
alive
=
True
db
.
close
()
self
.
shutdown_syncer
()
self
.
set_status
(
code
=
STATUS
[
'
UNINITIALIZED
'
])
self
.
close
()
def
_get_default_sync
(
self
):
"""
Get global.default_sync or pick the first sync as default
If there are no syncs, create a
'
default
'
sync.
...
...
@@ -639,6 +603,7 @@ class WebSocketProtocol(WebSocket):
if
action
==
'
shutdown
'
:
# Clean db to cause syncer backend to shut down
self
.
set_status
(
code
=
STATUS
[
'
SHUTTING DOWN
'
])
self
.
shutdown_syncer
()
retry_on_locked_db
(
self
.
clean_db
)
# self._shutdown()
# self.terminate()
...
...
@@ -651,7 +616,6 @@ class WebSocketProtocol(WebSocket):
self
.
send_json
({
'
OK
'
:
200
,
'
action
'
:
'
post %s
'
%
action
})
elif
r
[
'
ui_id
'
]
==
self
.
ui_id
:
self
.
accepted
=
True
Thread
(
target
=
self
.
heartbeat
).
start
()
self
.
send_json
({
'
ACCEPTED
'
:
202
,
'
action
'
:
'
post ui_id
'
})
self
.
_load_settings
()
if
(
not
self
.
syncer
)
and
self
.
can_sync
():
...
...
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