Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
6f4b9efa
Commit
6f4b9efa
authored
5 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Add some comments and remove debug code.
parent
7d4a1e6d
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
app/main/events.py
+18
-9
18 additions, 9 deletions
app/main/events.py
with
18 additions
and
9 deletions
app/main/events.py
+
18
−
9
View file @
6f4b9efa
...
@@ -16,9 +16,12 @@ disconnected = []
...
@@ -16,9 +16,12 @@ disconnected = []
@socketio.on
(
'
connect
'
)
@socketio.on
(
'
connect
'
)
@login_required
@login_required
def
connect
():
def
connect
():
# print('{} connected'.format(current_user.username))
'''
# send('You entered the room {}'.format(request.sid),
'
The Socket.IO module creates a session id (sid) on each request. The
# room=request.sid)
'
initiating client is automatically placed in a room with that sid, which
'
will be used for further information exchange generated by a background
'
task associated with the sid.
'''
socketio
.
start_background_task
(
background_task
,
socketio
.
start_background_task
(
background_task
,
current_user
.
id
,
current_user
.
id
,
request
.
sid
)
request
.
sid
)
...
@@ -27,8 +30,11 @@ def connect():
...
@@ -27,8 +30,11 @@ def connect():
@socketio.on
(
'
disconnect
'
)
@socketio.on
(
'
disconnect
'
)
@login_required
@login_required
def
disconnect
():
def
disconnect
():
'''
'
On disconnect the session id (sid) of the connection gets placed in the
'
disconnected list (see above).
'''
disconnected
.
append
(
request
.
sid
)
disconnected
.
append
(
request
.
sid
)
#print('{} disconnected'.format(current_user.username))
def
background_task
(
user_id
,
session_id
):
def
background_task
(
user_id
,
session_id
):
...
@@ -39,13 +45,19 @@ def background_task(user_id, session_id):
...
@@ -39,13 +45,19 @@ def background_task(user_id, session_id):
'
'
'
NOTE: The initial values are send as a init-* events.
'
NOTE: The initial values are send as a init-* events.
'
The JSON patches are send as update-* events.
'
The JSON patches are send as update-* events.
'
'
> where
'
*
'
is either
'
corpora
'
or
'
jobs
'
'''
'''
'
Create an app instance to get access to an app_context with which db
'
operations are fulfilled.
'''
'''
app
=
create_app
(
os
.
getenv
(
'
FLASK_CONFIG
'
)
or
'
default
'
,
main
=
False
)
app
=
create_app
(
os
.
getenv
(
'
FLASK_CONFIG
'
)
or
'
default
'
,
main
=
False
)
with
app
.
app_context
():
with
app
.
app_context
():
user
=
db
.
session
.
query
(
User
).
filter_by
(
id
=
user_id
).
first
()
user
=
db
.
session
.
query
(
User
).
filter_by
(
id
=
user_id
).
first
()
'''
Get current values from the database.
'''
'''
Get current values from the database.
'''
corpora
=
user
.
corpora_as_dict
()
corpora
=
user
.
corpora_as_dict
()
jobs
=
user
.
jobs_as_dict
()
jobs
=
user
.
jobs_as_dict
()
'''
Send initial values.
'''
'''
Send initial values.
'''
socketio
.
emit
(
'
init-corpora
'
,
socketio
.
emit
(
'
init-corpora
'
,
...
@@ -56,8 +68,6 @@ def background_task(user_id, session_id):
...
@@ -56,8 +68,6 @@ def background_task(user_id, session_id):
room
=
session_id
)
room
=
session_id
)
'''
TODO: Implement maximum runtime for this loop.
'''
'''
TODO: Implement maximum runtime for this loop.
'''
while
session_id
not
in
disconnected
:
while
session_id
not
in
disconnected
:
# print(session_id + ' running')
# socketio.emit('message', 'heartbeat', room=session_id)
'''
Get current values from the database
'''
'''
Get current values from the database
'''
new_corpora
=
user
.
corpora_as_dict
()
new_corpora
=
user
.
corpora_as_dict
()
new_jobs
=
user
.
jobs_as_dict
()
new_jobs
=
user
.
jobs_as_dict
()
...
@@ -73,9 +83,8 @@ def background_task(user_id, session_id):
...
@@ -73,9 +83,8 @@ def background_task(user_id, session_id):
socketio
.
emit
(
'
update-jobs
'
,
socketio
.
emit
(
'
update-jobs
'
,
jobs_patch
.
to_string
(),
jobs_patch
.
to_string
(),
room
=
session_id
)
room
=
session_id
)
'''
Set new values as
a
reference for the next iteration.
'''
'''
Set new values as reference
s
for the next iteration.
'''
corpora
=
new_corpora
corpora
=
new_corpora
jobs
=
new_jobs
jobs
=
new_jobs
socketio
.
sleep
(
3
)
socketio
.
sleep
(
3
)
disconnected
.
remove
(
session_id
)
disconnected
.
remove
(
session_id
)
# print(session_id + ' stopped')
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