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
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
3de48946
Commit
3de48946
authored
5 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Update job database entries on status change.
parent
9d0d3869
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/__init__.py
+1
-3
1 addition, 3 deletions
app/__init__.py
app/swarm.py
+29
-9
29 additions, 9 deletions
app/swarm.py
with
30 additions
and
12 deletions
app/__init__.py
+
1
−
3
View file @
3de48946
...
@@ -5,12 +5,9 @@ from flask_mail import Mail
...
@@ -5,12 +5,9 @@ from flask_mail import Mail
from
flask_sqlalchemy
import
SQLAlchemy
from
flask_sqlalchemy
import
SQLAlchemy
from
.swarm
import
Swarm
from
.swarm
import
Swarm
db
=
SQLAlchemy
()
db
=
SQLAlchemy
()
login_manager
=
LoginManager
()
login_manager
=
LoginManager
()
login_manager
.
login_view
=
'
auth.login
'
login_manager
.
login_view
=
'
auth.login
'
mail
=
Mail
()
mail
=
Mail
()
swarm
=
Swarm
()
swarm
=
Swarm
()
...
@@ -23,6 +20,7 @@ def create_app(config_name):
...
@@ -23,6 +20,7 @@ def create_app(config_name):
db
.
init_app
(
app
)
db
.
init_app
(
app
)
login_manager
.
init_app
(
app
)
login_manager
.
init_app
(
app
)
mail
.
init_app
(
app
)
mail
.
init_app
(
app
)
swarm
.
init_app
(
app
)
from
.auth
import
auth
as
auth_blueprint
from
.auth
import
auth
as
auth_blueprint
app
.
register_blueprint
(
auth_blueprint
,
url_prefix
=
'
/auth
'
)
app
.
register_blueprint
(
auth_blueprint
,
url_prefix
=
'
/auth
'
)
...
...
This diff is collapsed.
Click to expand it.
app/swarm.py
+
29
−
9
View file @
3de48946
from
sqlalchemy
import
create_engine
from
sqlalchemy.orm
import
sessionmaker
import
docker
import
docker
import
time
import
time
import
json
import
json
...
@@ -5,9 +7,16 @@ import os
...
@@ -5,9 +7,16 @@ import os
class
Swarm
:
class
Swarm
:
def
__init__
(
self
):
def
__init__
(
self
,
app
=
None
):
self
.
app
=
app
if
app
is
not
None
:
self
.
init_app
(
app
)
self
.
docker
=
docker
.
from_env
()
self
.
docker
=
docker
.
from_env
()
def
init_app
(
self
,
app
):
engine
=
create_engine
(
app
.
config
[
'
SQLALCHEMY_DATABASE_URI
'
])
self
.
Session
=
sessionmaker
(
bind
=
engine
)
'''
'''
'
Swarm mode is intendet to run containers which serve a non terminating
'
Swarm mode is intendet to run containers which serve a non terminating
'
service like a webserver. For processing an occuring job it is necessary
'
service like a webserver. For processing an occuring job it is necessary
...
@@ -81,18 +90,29 @@ class Swarm:
...
@@ -81,18 +90,29 @@ class Swarm:
restart_policy
=
_restart_policy
restart_policy
=
_restart_policy
)
)
'''
'''
'
Because it takes some time until all data in the service object is
'
initialized (especcially the task list returned by the service.tasks
'
method), a poll loop checks if the task list is empty.
'''
while
not
service
.
tasks
():
time
.
sleep
(
1
)
service
.
reload
()
'''
'
Poll the service until the job is completly executed.
'
Poll the service until the job is completly executed.
'
'
Note: Because it takes some time until all data in the service object
'
is initialized (especcially the task list returned by the tasks
'
method) the poll loop also checks if the task list is empy (The
'
not service.tasks() condition implements this).
'''
'''
print
(
service
.
attrs
)
session
=
self
.
Session
()
while
not
service
.
tasks
()
or
\
while
True
:
service
.
tasks
()[
0
].
get
(
'
Status
'
).
get
(
'
State
'
)
!=
'
complete
'
:
current_state
=
service
.
tasks
()[
0
].
get
(
'
Status
'
).
get
(
'
State
'
)
if
job
.
status
!=
current_state
:
job
.
status
=
current_state
session
.
add
(
job
)
session
.
commit
()
print
(
current_state
)
if
current_state
==
'
complete
'
:
break
time
.
sleep
(
1
)
time
.
sleep
(
1
)
service
.
reload
()
service
.
reload
()
session
.
close
()
# Remove the service from the swarm.
# Remove the service from the swarm.
service
.
remove
()
service
.
remove
()
...
...
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