Skip to content

Commit

Permalink
move database call out
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Sep 20, 2023
1 parent 05e8126 commit 4d5c2f7
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions spinnman/spalloc/spalloc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(
logger.info("established session to {} for {}", service_url, username)

@staticmethod
def open_job_from_database(conn: sqlite3.Cursor) -> SpallocJob:
def open_job_from_database(service_url, job_url, cookies, headers) -> SpallocJob:
"""
Create a job from the description in the attached database. This is
intended to allow for access to the job's allocated resources from
Expand All @@ -110,35 +110,16 @@ def open_job_from_database(conn: sqlite3.Cursor) -> SpallocJob:
credentials may have expired; if so, the job will be unable to
regenerate them.
:param ~sqlite3.Cursor conn:
The database cursor to retrieve the job details from. Assumes
the presence of a ``proxy_configuration`` table with ``kind``,
``name`` and ``value`` columns.
:param str service_url:
:param str job_url:
:param dict(str, str) cookies:
:param dict(str, str) headers:
:return:
The job handle, or ``None`` if the records in the database are
absent or incomplete.
:rtype: SpallocJob
"""
service_url = None
job_url = None
cookies = {}
headers = {}
for row in conn.execute("""
SELECT kind, name, value FROM proxy_configuration
"""):
kind, name, value = row
if kind == "SPALLOC":
if name == "service uri":
service_url = value
elif name == "job uri":
job_url = value
elif kind == "COOKIE":
cookies[name] = value
elif kind == "HEADER":
headers[name] = value
if not service_url or not job_url or not cookies or not headers:
# Cannot possibly work without a session or job
return None
session = Session(service_url, session_credentials=(cookies, headers))
return _SpallocJob(session, job_url)

Expand Down

0 comments on commit 4d5c2f7

Please sign in to comment.