From a5687a3f1b9c9bd021eea583a8cb9e052e2fc24e Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Mon, 12 Aug 2019 19:34:24 +0200 Subject: [PATCH] Use scoped_session correctly. --- app/scheduler.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/scheduler.py b/app/scheduler.py index 01437b75..cf8b9f1e 100644 --- a/app/scheduler.py +++ b/app/scheduler.py @@ -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()