Skip to content

Commit efa3c24

Browse files
Merge pull request #3299 from antgonza/2023.06-fixes-rc
2023.06-fixes-rc
2 parents 9c70efb + 7b807b1 commit efa3c24

File tree

9 files changed

+63
-39
lines changed

9 files changed

+63
-39
lines changed

qiita_db/handlers/artifact.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,5 +320,4 @@ def post(self):
320320
r_client.set('prep_template_%d' % prep_id,
321321
dumps({'job_id': new_job.id, 'is_qiita_job': True}))
322322

323-
self.write(new_job.id)
324-
self.finish()
323+
self.finish({'job_id': new_job.id})

qiita_db/handlers/tests/test_artifact.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def test_post(self):
368368
# send the new data
369369
del data['prep_id']
370370
obs = self.post('/qiita_db/artifact/', headers=self.header, data=data)
371-
jid = obs.body.decode("utf-8")
371+
jid = loads(obs.body)['job_id']
372372

373373
job = qdb.processing_job.ProcessingJob(jid)
374374
while job.status not in ('error', 'success'):
@@ -404,7 +404,7 @@ def test_post(self):
404404
'files': dumps({'biom': [fp]})}
405405

406406
obs = self.post('/qiita_db/artifact/', headers=self.header, data=data)
407-
jid = obs.body.decode("utf-8")
407+
jid = loads(obs.body)['job_id']
408408

409409
job = qdb.processing_job.ProcessingJob(jid)
410410
while job.status not in ('error', 'success'):

qiita_db/handlers/tests/test_prep_template.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ def test_post(self):
172172
self.assertEqual(pt.name, data['name'])
173173
self.assertEqual(pt.creation_job_id, data['job-id'])
174174

175+
# testing setter
176+
jid = 'aaaaaaaa-aaaa-bbbb-aaaa-aaaaaaaaaaaa'
177+
pt.creation_job_id = jid
178+
self.assertEqual(pt.creation_job_id, jid)
179+
175180

176181
if __name__ == '__main__':
177182
main()

qiita_db/metadata_template/prep_template.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,3 +970,12 @@ def creation_job_id(self):
970970
WHERE prep_template_id = %s"""
971971
qdb.sql_connection.TRN.add(sql, [self.id])
972972
return qdb.sql_connection.TRN.execute_fetchlast()
973+
974+
@creation_job_id.setter
975+
def creation_job_id(self, creation_job_id):
976+
with qdb.sql_connection.TRN:
977+
sql = """UPDATE qiita.prep_template
978+
SET creation_job_id = %s
979+
WHERE prep_template_id = %s"""
980+
qdb.sql_connection.TRN.add(sql, [creation_job_id, self.id])
981+
qdb.sql_connection.TRN.execute()

qiita_pet/handlers/admin_processing_job.py

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from qiita_db.software import Software
1616
from qiita_db.study import Study
1717
from qiita_db.exceptions import QiitaDBUnknownIDError
18+
from qiita_db.sql_connection import TRN
19+
from qiita_db.processing_job import ProcessingJob as PJ
1820

1921
from json import dumps
2022
from collections import Counter
@@ -57,35 +59,44 @@ def get(self):
5759
echo = self.get_argument('sEcho')
5860
command_id = int(self.get_argument('commandId'))
5961

60-
jobs = []
61-
for ps in self._get_private_software():
62-
for cmd in ps.commands:
63-
if cmd.id != command_id:
64-
continue
62+
with TRN:
63+
# different versions of the same plugin will have different
64+
# command_id, this will make sure to get them all (commands)
65+
sql = """SELECT processing_job_id FROM qiita.processing_job
66+
WHERE hidden = false and command_id in (
67+
SELECT command_id FROM qiita.software_command
68+
WHERE
69+
name in (
70+
SELECT name FROM qiita.software_command
71+
WHERE command_id = %s)) AND
72+
(heartbeat > current_date - interval '14' day OR
73+
heartbeat is NULL)"""
74+
TRN.add(sql, [command_id])
75+
jids = TRN.execute_fetchflatten()
6576

66-
for job in cmd.processing_jobs:
67-
if job.hidden:
68-
continue
69-
msg = ''
70-
if job.status == 'error':
71-
msg = job.log.msg
72-
elif job.status == 'running':
73-
msg = job.step
74-
msg = msg.replace('\n', '</br>')
75-
outputs = []
76-
if job.status == 'success':
77-
outputs = [[k, v.id] for k, v in job.outputs.items()]
78-
validator_jobs = [v.id for v in job.validator_jobs]
79-
80-
if job.heartbeat is not None:
81-
heartbeat = job.heartbeat.strftime('%Y-%m-%d %H:%M:%S')
82-
else:
83-
heartbeat = 'N/A'
84-
85-
jobs.append([job.id, job.command.name, job.status, msg,
86-
outputs, validator_jobs, heartbeat,
87-
job.parameters.values, job.external_id,
88-
job.user.email])
77+
jobs = []
78+
for jid in jids:
79+
job = PJ(jid)
80+
msg = ''
81+
if job.status == 'error':
82+
msg = job.log.msg
83+
elif job.status == 'running':
84+
msg = job.step
85+
msg = msg.replace('\n', '</br>')
86+
outputs = []
87+
if job.status == 'success':
88+
outputs = [[k, v.id] for k, v in job.outputs.items()]
89+
validator_jobs = [v.id for v in job.validator_jobs]
90+
91+
if job.heartbeat is not None:
92+
heartbeat = job.heartbeat.strftime('%Y-%m-%d %H:%M:%S')
93+
else:
94+
heartbeat = 'N/A'
95+
96+
jobs.append([job.id, job.command.name, job.status, msg,
97+
outputs, validator_jobs, heartbeat,
98+
job.parameters.values, job.external_id,
99+
job.user.email])
89100
results = {
90101
"sEcho": echo,
91102
"recordsTotal": len(jobs),

qiita_pet/handlers/study_handlers/prep_template.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ def get(self):
7676
res['alert_message'] = url_escape(res['alert_message'])
7777
res['user_level'] = current_user.level
7878
if res['creation_job'] is not None:
79-
vals = res['creation_job'].values
80-
res['creation_job_filename'] = vals['filename']
81-
res['creation_job_filename_body'] = vals['body']
79+
fp = res['creation_job'].parameters.values['sample_sheet']
80+
res['creation_job_filename'] = fp['filename']
81+
res['creation_job_filename_body'] = fp['body']
8282

8383
self.render('study_ajax/prep_summary.html', **res)
8484

qiita_pet/templates/admin_processing_job.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@
7171
};
7272

7373
out.push('<b class="' + statusToClass[status] + '">' + status + ' ' +
74-
row[0] + ' </b> [ ' + row[9] + ' ]</br>');
74+
row[0] + ' (' + row[8] + ') </b> [ ' + row[9] + ' ]</br>');
7575

7676
if (status === 'running' || status === 'queued') {
7777
// row[0] is qiita job-id
7878
// row[3] is status 'Step n of 6' and other messages
79-
out.push('[' + row[8] + ']</br> <i>' + row[3] + '</i>')
79+
out.push('<i>' + row[3] + '</i>')
8080
}
8181
else {
8282
// We write a callback attribute on the link to be able to display a

qiita_pet/templates/study_ajax/prep_summary.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ <h4>
431431

432432
<span id="prep-name-span">{{name}}</span> - ID {{prep_id}} ({{data_type}})
433433
{% if user_level in ('admin', 'wet-lab admin') and creation_job is not None %}
434-
<a class="btn btn-default" download="{{creation_job_filename}}" href="data:text/plain;charset=utf-8,encodeURIComponent({{creation_job_filename_body}})"><span class="glyphicon glyphicon-download-alt"></span> SampleSheet</a>
434+
<a class="btn btn-default" download="{{creation_job_filename}}" href="data:text/plain;charset=utf-8,{{creation_job_filename_body}}"><span class="glyphicon glyphicon-download-alt"></span> SampleSheet</a>
435435
{% end %}
436436
<a class="btn btn-default" data-toggle="modal" data-target="#update-prep-name"><span class="glyphicon glyphicon-pencil"></span> Edit name</a>
437437
<a class="btn btn-default" href="{% raw qiita_config.portal_dir %}/download/{{download_prep_id}}"><span class="glyphicon glyphicon-download-alt"></span> Prep info</a>

qiita_pet/test/test_admin_processing_job_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_get(self):
3232

3333
class TestAJAXAdminProcessingJobListing(BaseAdminTests):
3434
def test_get(self):
35-
response = self.get('/admin/processing_jobs/list?sEcho=3&commandId=1')
35+
response = self.get('/admin/processing_jobs/list?sEcho=3&commandId=2')
3636
self.assertEqual(response.code, 200)
3737

3838
exp = {'sEcho': '3', 'recordsTotal': 0, 'recordsFiltered': 0,

0 commit comments

Comments
 (0)