|
15 | 15 | from qiita_db.software import Software
|
16 | 16 | from qiita_db.study import Study
|
17 | 17 | from qiita_db.exceptions import QiitaDBUnknownIDError
|
| 18 | +from qiita_db.sql_connection import TRN |
| 19 | +from qiita_db.processing_job import ProcessingJob as PJ |
18 | 20 |
|
19 | 21 | from json import dumps
|
20 | 22 | from collections import Counter
|
@@ -57,35 +59,44 @@ def get(self):
|
57 | 59 | echo = self.get_argument('sEcho')
|
58 | 60 | command_id = int(self.get_argument('commandId'))
|
59 | 61 |
|
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() |
65 | 76 |
|
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]) |
89 | 100 | results = {
|
90 | 101 | "sEcho": echo,
|
91 | 102 | "recordsTotal": len(jobs),
|
|
0 commit comments