Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to run jobs from flowcharts or previous jobs. #146

Merged
merged 18 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion seamm_dashboard/jwt_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@


def _decode_jwt_from_cookies(refresh):

try:
csrf_protect = config.csrf_protect
except AttributeError:
csrf_protect = config.cookie_csrf_protect

if refresh:
cookie_key = config.refresh_cookie_name
csrf_header_key = config.refresh_csrf_header_name
Expand All @@ -37,7 +43,7 @@ def _decode_jwt_from_cookies(refresh):
raise NoAuthorizationError('Missing cookie "{}"'.format(cookie_key))

if (
config.csrf_protect
csrf_protect
and request.method in config.csrf_request_methods
and current_app.config["JWT_CSRF_ACCESS_PATH"] in request.url
):
Expand Down
6 changes: 5 additions & 1 deletion seamm_dashboard/results_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
def run():
app = create_app()

# serve using waitress
if "debug" in options:
app.run(debug=True, use_reloader=True)
else:
# serve using waitress
serve(app, port=options["port"])
if options["localhost"]:
serve(app, listen=f"localhost:{options['port']}", threads=12)
else:
serve(app, port=options["port"], threads=12)


if __name__ == "__main__":
Expand Down
58 changes: 1 addition & 57 deletions seamm_dashboard/routes/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import shutil
from datetime import datetime, timezone
import fasteners
import json
import logging
from pathlib import Path
Expand All @@ -17,6 +16,7 @@
from flask_jwt_extended import jwt_required, get_current_user

from seamm_dashboard import db, datastore, options
from seamm_dashboard.util import get_job_id
from seamm_datastore.database.models import Job, Role
from seamm_datastore.database.schema import JobSchema

Expand Down Expand Up @@ -80,62 +80,6 @@ def get_jobs(
return jsonify(jobs), 200


def get_job_id(filename):
"""Get the next job id from the given file.

This uses the fasteners module to provide locking so that
only one job at a time can access the file, so that the job
ids are unique and monotonically increasing.
"""

filename = os.path.expanduser(filename)

lock_file = filename + ".lock"
lock = fasteners.InterProcessLock(lock_file)
locked = lock.acquire(blocking=True, timeout=5)

if locked:
if not os.path.isfile(filename):
job_id = 1
with open(filename, "w") as fd:
fd.write("!MolSSI job_id 1.0\n")
fd.write("1\n")
lock.release()
else:
with open(filename, "r+") as fd:
line = fd.readline()
pos = fd.tell()
if line == "":
lock.release()
raise EOFError("job_id file '{}' is empty".format(filename))
line = line.strip()
match = re.fullmatch(r"!MolSSI job_id ([0-9]+(?:\.[0-9]+)*)", line)
if match is None:
lock.release()
raise RuntimeError(
"The job_id file has an incorrect header: {}".format(line)
)
line = fd.readline()
if line == "":
lock.release()
raise EOFError("job_id file '{}' is truncated".format(filename))
try:
job_id = int(line)
except TypeError:
raise TypeError(
"The job_id in file '{}' is not an integer: {}".format(
filename, line
)
)
job_id += 1
fd.seek(pos)
fd.write("{:d}\n".format(job_id))
else:
raise RuntimeError("Could not lock the job_id file '{}'".format(filename))

return job_id


@jwt_required(optional=True)
def add_job(body):
"""Add a new job to the queue.
Expand Down
8 changes: 7 additions & 1 deletion seamm_dashboard/routes/jobs/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask_wtf import FlaskForm
from flask_wtf.file import FileField
from wtforms import StringField, TextAreaField, SubmitField
from wtforms import StringField, TextAreaField, SubmitField, SelectMultipleField


from wtforms.validators import DataRequired, Length, Regexp

Expand All @@ -27,3 +28,8 @@ class ImportJob(FlaskForm):
outfile = FileField("job_data.json File", validators=[DataRequired()])
title = StringField("Job Title")
submit = SubmitField("Import Job")


class GetFlowchart(FlaskForm):
outfile = FileField("File (*.flow)", validators=[DataRequired()])
submit = SubmitField("Upload flowchart")
Loading
Loading