Skip to content

Commit

Permalink
update_job_status() now has option to ignore runtime errors
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cowart committed Jul 16, 2024
1 parent d4e83b7 commit ab9cad8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
10 changes: 8 additions & 2 deletions qiita_client/qiita_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def get_job_info(self, job_id):
logger.debug('Entered QiitaClient.get_job_info()')
return self.get("/qiita_db/jobs/%s" % job_id)

def update_job_step(self, job_id, new_step):
def update_job_step(self, job_id, new_step, ignore_error=False):
"""Updates the current step of the job in the server
Parameters
Expand All @@ -536,10 +536,16 @@ def update_job_step(self, job_id, new_step):
The job id
new_step : str
The new step
ignore_error : bool
Problems communicating w/Qiita will not raise an Error.
"""
logger.debug('Entered QiitaClient.update_job_step()')
json_payload = dumps({'step': new_step})
self.post("/qiita_db/jobs/%s/step/" % job_id, data=json_payload)
try:
self.post("/qiita_db/jobs/%s/step/" % job_id, data=json_payload)
except RuntimeError as e:
if ignore_error is True:
raise e

def complete_job(self, job_id, success, error_msg=None,
artifacts_info=None):
Expand Down
26 changes: 26 additions & 0 deletions qiita_client/tests/test_qiita_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from qiita_client.exceptions import BadRequestError

CLIENT_ID = '19ndkO3oMKsoChjVVWluF7QkxHRfYhTKSFbAVt8IhK7gZgDaO4'
BAD_CLIENT_ID = 'NOT_A_CLIENT_ID'
CLIENT_SECRET = ('J7FfQ7CQdOxuKhQAf1eoGgBAE81Ns8Gu3EKaWFm3IO2JKh'
'AmmCWZuabe0O5Mp28s1')

Expand Down Expand Up @@ -99,6 +100,9 @@ def setUp(self):
self.server_cert = environ.get('QIITA_SERVER_CERT', None)
self.tester = QiitaClient("https://localhost:21174", CLIENT_ID,
CLIENT_SECRET, server_cert=self.server_cert)
self.bad_tester = QiitaClient("https://localhost:21174", BAD_CLIENT_ID,
CLIENT_SECRET,
server_cert=self.server_cert)
self.clean_up_files = []

# making assertRaisesRegex compatible with Python 2.7 and 3.9
Expand Down Expand Up @@ -232,6 +236,28 @@ def test_update_job_step(self):
obs = self.tester.update_job_step(job_id, new_step)
self.assertIsNone(obs)

def test_update_job_step_ignore_failure(self):
job_id = "bcc7ebcd-39c1-43e4-af2d-822e3589f14d"
new_step = "some new step"

# confirm that update_job_step behaves as before when ignore_error
# parameter absent or set to False.

with self.assertRaises(RuntimeError):
self.bad_tester.update_job_step(job_id, new_step)

with self.assertRaises(RuntimeError):
self.bad_tester.update_job_step(job_id, new_step,
ignore_error=False)

# confirm that when ignore_error is set to True, an Error is NOT
# raised.
try:
self.bad_tester.update_job_step(job_id, new_step,
ignore_error=True)
except RuntimeError:
self.fail("update_job_step raised RuntimeError unexpectedly")

def test_complete_job(self):
# Create a new job
data = {
Expand Down

0 comments on commit ab9cad8

Please sign in to comment.