mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Use scoped_session correctly.
This commit is contained in:
parent
faf54e57fa
commit
a5687a3f1b
@ -14,8 +14,7 @@ class Scheduler(BackgroundScheduler):
|
||||
|
||||
def init_app(self, app):
|
||||
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
|
||||
self.session_factory = sessionmaker(bind=engine)
|
||||
self.Session = scoped_session(self.session_factory)
|
||||
self.Session = scoped_session(sessionmaker(bind=engine))
|
||||
if not app.debug or os.environ.get('WERKZEUG_RUN_MAIN') == 'true':
|
||||
self.add_job(self.check_jobs, id='jobs', seconds=10, trigger='interval')
|
||||
self.start()
|
||||
@ -24,15 +23,14 @@ class Scheduler(BackgroundScheduler):
|
||||
from .models import Job
|
||||
from . import swarm
|
||||
|
||||
Session = scoped_session(self.session_factory)
|
||||
session = Session()
|
||||
session = self.Session()
|
||||
jobs = session.query(Job)
|
||||
submitted_jobs = jobs.filter_by(status='submitted').all()
|
||||
foo_jobs = jobs.filter(Job.status != 'complete',
|
||||
Job.status != 'failed',
|
||||
Job.status != 'submitted').all()
|
||||
for job in submitted_jobs:
|
||||
swarm.run(job.id)
|
||||
swarm.run(job)
|
||||
job.status = 'scheduled'
|
||||
for job in foo_jobs:
|
||||
'''
|
||||
@ -44,4 +42,4 @@ class Scheduler(BackgroundScheduler):
|
||||
job.end_date = datetime.utcnow()
|
||||
service.remove()
|
||||
session.commit()
|
||||
Session.remove()
|
||||
self.Session.remove()
|
||||
|
Loading…
Reference in New Issue
Block a user