Skip to content

Commit 44e9f69

Browse files
add Command.processing_jobs (#3085)
* add Command.processing_jobs * Update qiita_db/software.py [skip ci] Co-authored-by: Yoshiki Vázquez Baeza <yoshiki@ucsd.edu> Co-authored-by: Yoshiki Vázquez Baeza <yoshiki@ucsd.edu>
1 parent 0f74fe9 commit 44e9f69

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

qiita_db/software.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,26 @@ def resource_allocation(self):
754754

755755
return result[0]
756756

757+
@property
758+
def processing_jobs(self):
759+
"""All the processing_jobs that used this command
760+
761+
Returns
762+
-------
763+
list of qiita_db.processing_job.ProcessingJob
764+
List of jobs that used this command.
765+
"""
766+
767+
with qdb.sql_connection.TRN:
768+
sql = """SELECT processing_job_id FROM
769+
qiita.processing_job
770+
WHERE command_id = %s"""
771+
qdb.sql_connection.TRN.add(sql, [self.id])
772+
773+
jids = qdb.sql_connection.TRN.execute_fetchflatten()
774+
775+
return [qdb.processing_job.ProcessingJob(j) for j in jids]
776+
757777

758778
class Software(qdb.base.QiitaObject):
759779
r"""A software package available in the system

qiita_db/test/test_software.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,23 @@ def test_activate(self):
464464
tester.activate()
465465
self.assertTrue(tester.active)
466466

467+
def test_processing_jobs(self):
468+
exp_jids = ['6d368e16-2242-4cf8-87b4-a5dc40bb890b',
469+
'4c7115e8-4c8e-424c-bf25-96c292ca1931',
470+
'b72369f9-a886-4193-8d3d-f7b504168e75',
471+
'46b76f74-e100-47aa-9bf2-c0208bcea52d',
472+
'6ad4d590-4fa3-44d3-9a8f-ddbb472b1b5f',
473+
'063e553b-327c-4818-ab4a-adfe58e49860',
474+
'ac653cb5-76a6-4a45-929e-eb9b2dee6b63']
475+
exp = [qdb.processing_job.ProcessingJob(j) for j in exp_jids]
476+
self.assertCountEqual(qdb.software.Command(1).processing_jobs, exp)
477+
478+
exp_jids = ['bcc7ebcd-39c1-43e4-af2d-822e3589f14d']
479+
exp = [qdb.processing_job.ProcessingJob(j) for j in exp_jids]
480+
self.assertCountEqual(qdb.software.Command(2).processing_jobs, exp)
481+
482+
self.assertCountEqual(qdb.software.Command(4).processing_jobs, [])
483+
467484

468485
@qiita_test_checker()
469486
class SoftwareTestsIter(TestCase):

0 commit comments

Comments
 (0)