-
Couldn't load subscription status.
- Fork 79
Fix 2321 #2522
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
Fix 2321 #2522
Changes from all commits
1c87f00
ff87431
b1924c3
5e0f643
115e3d8
b549d22
2dd0732
4983720
7666b06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| # ----------------------------------------------------------------------------- | ||
|
|
||
| from __future__ import division | ||
| from collections import defaultdict | ||
| from future.utils import viewitems | ||
| from copy import deepcopy | ||
| from itertools import chain | ||
|
|
@@ -43,9 +44,6 @@ | |
| import qiita_db as qdb | ||
|
|
||
|
|
||
| _VALID_EBI_STATUS = ('not submitted', 'submitting', 'submitted') | ||
|
|
||
|
|
||
| class Study(qdb.base.QiitaObject): | ||
| r"""Study object to access to the Qiita Study information | ||
|
|
||
|
|
@@ -81,8 +79,7 @@ class Study(qdb.base.QiitaObject): | |
| _table = "study" | ||
| _portal_table = "study_portal" | ||
| # The following columns are considered not part of the study info | ||
| _non_info = frozenset(["email", "study_title", "ebi_submission_status", | ||
| "ebi_study_accession"]) | ||
| _non_info = frozenset(["email", "study_title", "ebi_study_accession"]) | ||
|
|
||
| def _lock_non_sandbox(self): | ||
| """Raises QiitaDBStatusError if study is non-sandboxed""" | ||
|
|
@@ -212,10 +209,19 @@ def get_info(cls, study_ids=None, info_cols=None): | |
| args.append(tuple(study_ids)) | ||
|
|
||
| qdb.sql_connection.TRN.add(sql, args) | ||
| res = qdb.sql_connection.TRN.execute_fetchindex() | ||
| if study_ids is not None and len(res) != len(study_ids): | ||
| rows = qdb.sql_connection.TRN.execute_fetchindex() | ||
| if study_ids is not None and len(rows) != len(study_ids): | ||
| raise qdb.exceptions.QiitaDBError( | ||
| 'Non-portal-accessible studies asked for!') | ||
|
|
||
| res = [] | ||
| for r in rows: | ||
| r = dict(r) | ||
| if 'ebi_study_accession' in info_cols: | ||
| r['ebi_submission_status'] = cls( | ||
| r['study_id']).ebi_submission_status | ||
| res.append(r) | ||
|
|
||
| return res | ||
|
|
||
| @classmethod | ||
|
|
@@ -825,39 +831,58 @@ def ebi_submission_status(self): | |
| ------- | ||
| str | ||
| The study EBI submission status | ||
| """ | ||
| with qdb.sql_connection.TRN: | ||
| sql = """SELECT ebi_submission_status | ||
| FROM qiita.{0} | ||
| WHERE study_id = %s""".format(self._table) | ||
| qdb.sql_connection.TRN.add(sql, [self.id]) | ||
| return qdb.sql_connection.TRN.execute_fetchlast() | ||
|
|
||
| @ebi_submission_status.setter | ||
| def ebi_submission_status(self, value): | ||
| """Sets the study's EBI submission status | ||
|
|
||
| Parameters | ||
| ---------- | ||
| value : str {%s} | ||
| The new EBI submission status | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError | ||
| If the status is not known | ||
| Notes | ||
| ----- | ||
| There are 4 possible states: 'not submitted', 'submitting', | ||
| 'submitted' & 'failed'. We are going to assume 'not submitted' if the | ||
| study doesn't have an accession, 'submitted' if it has an accession, | ||
| 'submitting' if there are submit_to_EBI jobs running using the study | ||
| artifacts, & 'failed' if there are artifacts with failed jobs without | ||
| successful ones. | ||
| """ | ||
| if not (value in _VALID_EBI_STATUS or | ||
| value.startswith('failed')): | ||
| raise ValueError("Unknown status: %s" % value) | ||
| status = 'not submitted' | ||
| with qdb.sql_connection.TRN: | ||
| sql = """UPDATE qiita.{} | ||
| SET ebi_submission_status = %s | ||
| WHERE study_id = %s""".format(self._table) | ||
| qdb.sql_connection.TRN.add(sql, [value, self.id]) | ||
| qdb.sql_connection.TRN.execute() | ||
|
|
||
| ebi_submission_status.__doc__.format(', '.join(_VALID_EBI_STATUS)) | ||
| if self.ebi_study_accession: | ||
| status = 'submitted' | ||
|
|
||
| plugin = qdb.software.Software.from_name_and_version( | ||
| 'Qiita', 'alpha') | ||
| cmd = plugin.get_command('submit_to_EBI') | ||
|
|
||
| sql = """SELECT processing_job_id, command_parameters->>'artifact', | ||
| processing_job_status | ||
| FROM qiita.processing_job | ||
| LEFT JOIN qiita.processing_job_status | ||
| USING (processing_job_status_id) | ||
| WHERE command_parameters->>'artifact' IN ( | ||
| SELECT artifact_id::text | ||
| FROM qiita.study_artifact | ||
| WHERE study_id = {0}) AND command_id = {1}""".format( | ||
| self._id, cmd.id) | ||
| qdb.sql_connection.TRN.add(sql) | ||
| jobs = defaultdict(dict) | ||
| for info in qdb.sql_connection.TRN.execute_fetchindex(): | ||
| jid, aid, js = info | ||
| jobs[js][aid] = jid | ||
|
|
||
| if 'queued' in jobs or 'running' in jobs: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of putting the logic in python, it might be possible to use postgres to only search for the jobs that have a status of "error", and if the query is empty then you can assume that it's still submitting, as there's not an accession available. Maybe it's more complicated, just thought I would share this idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the only issue with this option is that we will still have to deal with those jobs in a success state. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, got it, thanks! |
||
| status = 'submitting' | ||
| elif 'error' in jobs: | ||
| aids_error = [] | ||
| aids_other = [] | ||
| for s, aids in jobs.items(): | ||
| for aid in aids.keys(): | ||
| if s == 'error': | ||
| aids_error.append(aid) | ||
| else: | ||
| aids_other.append(aid) | ||
| difference = set(aids_error) - set(aids_other) | ||
| if difference: | ||
| status = ('Some artifact submissions failed: %s' % | ||
| ', '.join(map(str, list(difference)))) | ||
|
|
||
| return status | ||
|
|
||
| @property | ||
| def tags(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| -- March 7, 2018 | ||
| -- delete ebi_submission_status from study | ||
|
|
||
| ALTER TABLE qiita.study DROP ebi_submission_status; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should return here, right? If there's an accession there's likely no need for any of the compute done down below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nop, cause it could be that prep 1 was submitted and the study already has an accession but there is another prep being submitted which should and will overwrite this status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation.