Skip to content

2023.06-fixes-rc #3299

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

Merged
merged 10 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions qiita_db/handlers/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,4 @@ def post(self):
r_client.set('prep_template_%d' % prep_id,
dumps({'job_id': new_job.id, 'is_qiita_job': True}))

self.write(new_job.id)
self.finish()
self.finish({'job_id': new_job.id})
4 changes: 2 additions & 2 deletions qiita_db/handlers/tests/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def test_post(self):
# send the new data
del data['prep_id']
obs = self.post('/qiita_db/artifact/', headers=self.header, data=data)
jid = obs.body.decode("utf-8")
jid = loads(obs.body)['job_id']

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

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

job = qdb.processing_job.ProcessingJob(jid)
while job.status not in ('error', 'success'):
Expand Down
5 changes: 5 additions & 0 deletions qiita_db/handlers/tests/test_prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ def test_post(self):
self.assertEqual(pt.name, data['name'])
self.assertEqual(pt.creation_job_id, data['job-id'])

# testing setter
jid = 'aaaaaaaa-aaaa-bbbb-aaaa-aaaaaaaaaaaa'
pt.creation_job_id = jid
self.assertEqual(pt.creation_job_id, jid)


if __name__ == '__main__':
main()
9 changes: 9 additions & 0 deletions qiita_db/metadata_template/prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,3 +970,12 @@ def creation_job_id(self):
WHERE prep_template_id = %s"""
qdb.sql_connection.TRN.add(sql, [self.id])
return qdb.sql_connection.TRN.execute_fetchlast()

@creation_job_id.setter
def creation_job_id(self, creation_job_id):
with qdb.sql_connection.TRN:
sql = """UPDATE qiita.prep_template
SET creation_job_id = %s
WHERE prep_template_id = %s"""
qdb.sql_connection.TRN.add(sql, [creation_job_id, self.id])
qdb.sql_connection.TRN.execute()
67 changes: 39 additions & 28 deletions qiita_pet/handlers/admin_processing_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from qiita_db.software import Software
from qiita_db.study import Study
from qiita_db.exceptions import QiitaDBUnknownIDError
from qiita_db.sql_connection import TRN
from qiita_db.processing_job import ProcessingJob as PJ

from json import dumps
from collections import Counter
Expand Down Expand Up @@ -57,35 +59,44 @@ def get(self):
echo = self.get_argument('sEcho')
command_id = int(self.get_argument('commandId'))

jobs = []
for ps in self._get_private_software():
for cmd in ps.commands:
if cmd.id != command_id:
continue
with TRN:
# different versions of the same plugin will have different
# command_id, this will make sure to get them all (commands)
sql = """SELECT processing_job_id FROM qiita.processing_job
WHERE hidden = false and command_id in (
SELECT command_id FROM qiita.software_command
WHERE
name in (
SELECT name FROM qiita.software_command
WHERE command_id = %s)) AND
(heartbeat > current_date - interval '14' day OR
heartbeat is NULL)"""
TRN.add(sql, [command_id])
jids = TRN.execute_fetchflatten()

for job in cmd.processing_jobs:
if job.hidden:
continue
msg = ''
if job.status == 'error':
msg = job.log.msg
elif job.status == 'running':
msg = job.step
msg = msg.replace('\n', '</br>')
outputs = []
if job.status == 'success':
outputs = [[k, v.id] for k, v in job.outputs.items()]
validator_jobs = [v.id for v in job.validator_jobs]

if job.heartbeat is not None:
heartbeat = job.heartbeat.strftime('%Y-%m-%d %H:%M:%S')
else:
heartbeat = 'N/A'

jobs.append([job.id, job.command.name, job.status, msg,
outputs, validator_jobs, heartbeat,
job.parameters.values, job.external_id,
job.user.email])
jobs = []
for jid in jids:
job = PJ(jid)
msg = ''
if job.status == 'error':
msg = job.log.msg
elif job.status == 'running':
msg = job.step
msg = msg.replace('\n', '</br>')
outputs = []
if job.status == 'success':
outputs = [[k, v.id] for k, v in job.outputs.items()]
validator_jobs = [v.id for v in job.validator_jobs]

if job.heartbeat is not None:
heartbeat = job.heartbeat.strftime('%Y-%m-%d %H:%M:%S')
else:
heartbeat = 'N/A'

jobs.append([job.id, job.command.name, job.status, msg,
outputs, validator_jobs, heartbeat,
job.parameters.values, job.external_id,
job.user.email])
results = {
"sEcho": echo,
"recordsTotal": len(jobs),
Expand Down
6 changes: 3 additions & 3 deletions qiita_pet/handlers/study_handlers/prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def get(self):
res['alert_message'] = url_escape(res['alert_message'])
res['user_level'] = current_user.level
if res['creation_job'] is not None:
vals = res['creation_job'].values
res['creation_job_filename'] = vals['filename']
res['creation_job_filename_body'] = vals['body']
fp = res['creation_job'].parameters.values['sample_sheet']
res['creation_job_filename'] = fp['filename']
res['creation_job_filename_body'] = fp['body']

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

Expand Down
4 changes: 2 additions & 2 deletions qiita_pet/templates/admin_processing_job.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@
};

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

if (status === 'running' || status === 'queued') {
// row[0] is qiita job-id
// row[3] is status 'Step n of 6' and other messages
out.push('[' + row[8] + ']</br> <i>' + row[3] + '</i>')
out.push('<i>' + row[3] + '</i>')
}
else {
// We write a callback attribute on the link to be able to display a
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/templates/study_ajax/prep_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ <h4>

<span id="prep-name-span">{{name}}</span> - ID {{prep_id}} ({{data_type}})
{% if user_level in ('admin', 'wet-lab admin') and creation_job is not None %}
<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>
<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>
{% end %}
<a class="btn btn-default" data-toggle="modal" data-target="#update-prep-name"><span class="glyphicon glyphicon-pencil"></span> Edit name</a>
<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>
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/test/test_admin_processing_job_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_get(self):

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

exp = {'sEcho': '3', 'recordsTotal': 0, 'recordsFiltered': 0,
Expand Down