Пример #1
0
def check_queue(ip, port):
    app = Flask(__name__)
    app.config['SERVER_NAME'] = conf.SERVER_NAME
    app.add_url_rule('/pathfinder/download/<uuid>', 'download', download)

    with app.app_context():
        db = get_db()
        cur = db.cursor()
        cur.execute('select * from job where status == ?', ('R',))
        numjobs = 0
        mail = None
        for row in cur.fetchall():
            uuid, email, date, status = row
            # finished?
            pid = int(open(os.path.join(get_job_folder(uuid), 'run.pid'), 'r').read())
            if pid_exists(pid):
                numjobs += 1
            else:
                mail = Mail(app)
                msg = Message('[PathFinder] Your job is finished.', sender='*****@*****.**', recipients=[email, '*****@*****.**'])

                if os.path.exists(os.path.join(get_job_folder(uuid), 'pathway.pdb')):
                    cur.execute('update job set status = ? where uuid = ?', ('F',uuid))
                    msg.body = render_template('email.tpl', uuid=uuid, has_error=False)
                    msg.attach('pathway.pdb', 'text/pdb', open(os.path.join(get_job_folder(uuid), 'pathway.pdb')).read())
                else:
                    cur.execute('update job set status = ? where uuid = ?', ('E',uuid))
                    msg.body = render_template('email.tpl', uuid=uuid, has_error=True)

        if numjobs < NUMJOBS_CONCUR:
            cur.execute('select * from job where status == ?', ('Q',))
            for row in cur.fetchall():
                uuid, email, date, status = row
                newpid = client(ip, port, "SPAWN:%s" % uuid)
                open(os.path.join(get_job_folder(uuid), 'run.pid'), 'w').write(newpid)
                cur.execute('update job set status = ? where uuid = ?', ('R',uuid))
                numjobs += 1
                if numjobs >= NUMJOBS_CONCUR: break

        db.commit()
        db.close()

        if mail:
            try:
                mail.send(msg)
            except:
                pass
Пример #2
0
 def handle_spawn(self, uuid):
     cwd = os.getcwd()
     os.chdir(get_job_folder(uuid))
     os.system('/bin/csh ./run.com > run.out')
Пример #3
0
if __name__ == "__main__":
    app = Flask(__name__, template_folder=os.path.join(conf.BASEDIR, 'templates'))
    app.config['SERVER_NAME'] = conf.SERVER_NAME
    app.add_url_rule('/anmpathway.cgi/download/<uuid>/<filename>', 'download', download)
    app.add_url_rule('/anmpathway.cgi/download/<uuid>', 'download', download)
    app.add_url_rule('/anmpathway.cgi/status/<uuid>', 'status', status)

    mail = None

    with app.app_context():
        db = get_db()
        cur = db.cursor()
        cur.execute('select * from job where uuid == ?', (uuid,))
        uuid, email, date, status = cur.fetchone()

        open(os.path.join(get_job_folder(uuid), 'run.pid'), 'w').write(str(os.getpid()))
        cur.execute('update job set status = ? where uuid = ?', ('R',uuid))
        db.commit()

        mail = Mail(app)
        msg = Message('[ANMPathway] Your job has started.', sender=conf.ADMIN_EMAIL, recipients=[email], bcc=[conf.ADMIN_EMAIL, conf.EXTRA_EMAIL])
        msg.html = render_template('email_started.tpl', uuid=uuid)
        mail.send(msg)

        etime = time.time()
        cwd = os.getcwd()
        os.chdir(get_job_folder(uuid))
        os.system('/bin/csh ./run.com > run.out')
        etime = time.time() - etime

        mail = Mail(app)