diff --git a/app/__init__.py b/app/__init__.py
index 8cac4c4d3c0e959cdd895ee1d7a3d699c7e6545a..41ab537f0dbe127514f9cf036444bd9b7af7ed11 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -5,12 +5,9 @@ from flask_mail import Mail
 from flask_sqlalchemy import SQLAlchemy
 from .swarm import Swarm
 
-
 db = SQLAlchemy()
-
 login_manager = LoginManager()
 login_manager.login_view = 'auth.login'
-
 mail = Mail()
 swarm = Swarm()
 
@@ -23,6 +20,7 @@ def create_app(config_name):
     db.init_app(app)
     login_manager.init_app(app)
     mail.init_app(app)
+    swarm.init_app(app)
 
     from .auth import auth as auth_blueprint
     app.register_blueprint(auth_blueprint, url_prefix='/auth')
diff --git a/app/swarm.py b/app/swarm.py
index 5566e105f2f5a500e37affd0a86579df72d5143e..9988f2a4e45ad7e3631189f4fc4b6518b9d25f31 100644
--- a/app/swarm.py
+++ b/app/swarm.py
@@ -1,3 +1,5 @@
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
 import docker
 import time
 import json
@@ -5,9 +7,16 @@ import os
 
 
 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()
 
+    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
     ' service like a webserver. For processing an occuring job it is necessary
@@ -81,18 +90,29 @@ class Swarm:
             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.
-        '
-        ' 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)
-        while not service.tasks() or \
-                service.tasks()[0].get('Status').get('State') != 'complete':
+        session = self.Session()
+        while True:
+            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)
             service.reload()
+        session.close()
         # Remove the service from the swarm.
         service.remove()