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

Backend changes to fix 3323 #3330

Merged
merged 7 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
slurm_reservation
  • Loading branch information
antgonza committed Nov 16, 2023
commit 84f8859cb10b92d2d67126e47e07d084ed4c1afd
44 changes: 44 additions & 0 deletions qiita_db/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,3 +1177,47 @@ def _add_file(self, filename, filetype, data_type=None):
VALUES (%s, %s{1})""".format(col, dtid)
qdb.sql_connection.TRN.add(sql, [self._id, fpid])
qdb.sql_connection.TRN.execute()

def _slurm_reservation(self):
"""Helper method for the slurm_reservation property"""
with qdb.sql_connection.TRN:
sql = """SELECT slurm_reservation
FROM qiita.{0}
WHERE analysis_id = %s""".format(self._table)
qdb.sql_connection.TRN.add(sql, [self._id])
return qdb.sql_connection.TRN.execute_fetchflatten()

@property
def slurm_reservation(self):
"""Returns a valid reservation if it exists

Returns
-------
str or None
returns the slurm reservation or None
"""
slurm_reservation = self._slurm_reservation()

if slurm_reservation:
slurm_reservation = slurm_reservation[0]
cmd = f"scontrol show reservations {slurm_reservation}"
p_out, p_err, rv = qdb.processing_job._system_call(cmd)
if rv == 0:
return slurm_reservation

return None

@slurm_reservation.setter
def slurm_reservation(self, slurm_reservation):
"""Changes the slurm reservation of the analysis

Parameters
----------
slurm_reservation : str
New slurm_reservation for the analysis
"""
sql = """UPDATE qiita.{0}
SET slurm_reservation = %s
WHERE analysis_id = %s""".format(self._table)
qdb.sql_connection.perform_as_transaction(
sql, [slurm_reservation, self._id])
8 changes: 8 additions & 0 deletions qiita_db/test/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,14 @@ def test_is_public_make_public(self):

self.assertTrue(analysis.is_public)

def test_slurm_reservation(self):
analysis = qdb.analysis.Analysis(1)
self.assertIsNone(analysis.slurm_reservation)
text = 'this is a tests!'
charles-cowart marked this conversation as resolved.
Show resolved Hide resolved
analysis.slurm_reservation = text
self.assertEqual(analysis._slurm_reservation(), [text])
self.assertIsNone(analysis.slurm_reservation)


if __name__ == "__main__":
main()