Skip to content

Commit 2486cdb

Browse files
authored
fix UI for user not in db, add logging to submitter (#15)
1 parent 8a8e79f commit 2486cdb

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

web-conexs-api/src/slurm_submission_service/submitter.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import logging
44
import os
5+
import sys
56
import time
67
import uuid
78
from contextlib import contextmanager
@@ -88,19 +89,18 @@ def build_job_and_run(
8889
r = requests.post(url_submit, data=json.dumps(job_request), headers=headers)
8990

9091
if r.status_code != 200:
91-
print(r.status_code)
92-
raise Exception("Job submission response not successful")
92+
raise Exception(f"Job submission response not successful {r.status_code}")
9393

9494
response = r.json()
9595

9696
if "job_id" not in response:
97-
print(f"Error submitting {job_name}")
98-
print(pformat(job_request))
99-
print(pformat(response))
97+
logger.error(f"Error submitting {job_name}")
98+
logger.error(pformat(job_request))
99+
logger.error(pformat(response))
100100
raise Exception("Submission failed - no job id in response")
101101

102102
job_id = response["job_id"]
103-
print(f"Simulation job {job_name} has ID {job_id}")
103+
logger.info(f"Simulation job {job_name} has ID {job_id}")
104104

105105
return job_id
106106

@@ -111,8 +111,6 @@ def submit_orca(session, sim: Simulation):
111111
user = sim.person.identifier
112112
uid = uuid.uuid4()
113113

114-
print(f"{ROOT_DIR} {user}")
115-
116114
job_name = application_name + "-" + str(uid)
117115
working_dir = ROOT_DIR + user + "/" + job_name
118116
cluster_dir = CLUSTER_ROOT_DIR + user + "/" + job_name
@@ -163,6 +161,7 @@ def submit_orca(session, sim: Simulation):
163161
sim.status = SimulationStatus.submitted
164162
update_simulation(session, sim)
165163
except Exception:
164+
logger.exception("Error submitting orca job")
166165
sim.status = SimulationStatus.failed
167166
update_simulation(session, sim)
168167

@@ -260,12 +259,13 @@ def run_update():
260259
if j["account"] == SLURM_USER:
261260
job_map[j["job_id"]] = {"state": j["job_state"][0]}
262261

263-
print(f"Number of active jobs {len(active)}")
262+
if len(active) != 0:
263+
logger.info(f"Number of active jobs {len(active)}")
264264

265265
for a in active:
266266
if a.job_id in job_map:
267267
state = job_map[a.job_id]["state"]
268-
print(state)
268+
logger.debug(f"Job {a.job_id} has state {state}")
269269

270270
if state == JOB_RUNNING and a.status != SimulationStatus.running:
271271
a.status = SimulationStatus.running
@@ -285,6 +285,7 @@ def run_update():
285285

286286
else:
287287
# TODO better state for whatever slurm might return
288+
logger.error(f"Active job with id {a.job_id} not in job_map")
288289
a.status = SimulationStatus.failed
289290
update_simulation(session, a)
290291

@@ -295,11 +296,23 @@ def test_read():
295296
for sim in sims:
296297
if sim.simulation_type_id == 1:
297298
jf, calc = get_orca_jobfile_with_technique(session, sim.id)
298-
print(jf)
299299

300300

301301
def main():
302-
print("Running main loop")
302+
rootlogger = logging.getLogger()
303+
formatter = logging.Formatter(
304+
"%(asctime)s - %(levelname)s - %(name)s - %(message)s",
305+
datefmt="%Y-%m-%d %H:%M:%S",
306+
)
307+
308+
sh = logging.StreamHandler(sys.stdout)
309+
sh.setFormatter(formatter)
310+
rootlogger.addHandler(sh)
311+
rootlogger.setLevel(logging.DEBUG)
312+
rootlogger.debug("Logging Configured")
313+
314+
logger.info("Running main loop")
315+
303316
while True:
304317
try:
305318
run_update()
@@ -308,4 +321,4 @@ def main():
308321
except Exception:
309322
logger.exception("Error in update loop")
310323
time.sleep(10)
311-
print("Loop iteration complete")
324+
logger.info("Loop iteration complete")

web-conexs-api/src/web_conexs_api/crud.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,8 @@ def get_user(session, user_id):
334334
statement = select(Person).where(Person.identifier == user_id)
335335
person = session.exec(statement).first()
336336

337+
if person is None:
338+
# auth successful but not in db yet
339+
person = Person(id=None, identifier=user_id, admin=False)
340+
337341
return person

0 commit comments

Comments
 (0)