[ARVADOS] updated: 66787390db6d9dd69705c0689a2dc20cd6e1ffa7

git at public.curoverse.com git at public.curoverse.com
Mon Aug 17 18:37:22 EDT 2015


Summary of changes:
 sdk/python/arvados/__init__.py | 60 ++++++++++++++++++++----------------------
 sdk/python/tests/test_init.py  | 17 ++++++++----
 2 files changed, 40 insertions(+), 37 deletions(-)

       via  66787390db6d9dd69705c0689a2dc20cd6e1ffa7 (commit)
      from  507568431e26f0699a9a8d851a2c73470666354b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 66787390db6d9dd69705c0689a2dc20cd6e1ffa7
Author: Bryan Cosca <bcosc at curoverse.com>
Date:   Mon Aug 17 18:37:17 2015 -0400

    6600: still trying to make a spy

diff --git a/sdk/python/arvados/__init__.py b/sdk/python/arvados/__init__.py
index 5f59150..8d58ed8 100644
--- a/sdk/python/arvados/__init__.py
+++ b/sdk/python/arvados/__init__.py
@@ -40,53 +40,50 @@ logger.addHandler(log_handler)
 logger.setLevel(logging.DEBUG if config.get('ARVADOS_DEBUG')
                 else logging.WARNING)
 
-def __init__(self,api_client=None,num_retries=None):
-    self.num_retries = num_retries if num_retries is not None else 5
-
-#@retry_method
 def task_set_output(self,s,api_client=None):
 
     if not api_client:
         api_client = api('v1')
 
     ok = False
-    output_retry_loop = RetryLoop(num_retries=2)
+    output_retry_loop = RetryLoop(num_retries=2, backoff_start=0)
     for tries_left in output_retry_loop:
-        if not ok:
-            try:
-                print tries_left
-                result = api_client.job_tasks().update(uuid=self['uuid'],
-                                                    body={
-                                                          'output':s,
-                                                          'success':True,
-                                                          'progress':1.0
-                                                         }).execute()
-            except errors.ApiError as error:
-                print "ApiError {}".format(error)
-            except errors.HttpError as error:
-                if not retry.check_http_response_success(error.status_code):
-                    print "HttpError returned {}, retrying with {} tries left.".format(error.status_code,tries_left)
+        try:
+            result = api_client.job_tasks().update(uuid=self['uuid'],
+                                                body={
+                                                      'output':s,
+                                                      'success':True,
+                                                      'progress':1.0
+                                                     }).execute()
+            
+        except errors.ApiError as error:
+            logger.debug("ApiError {}, retrying with {} tries_left".format(error,tries_left+1))
+        except errors.HttpError as error:
+            if not retry.check_http_response_success(error.status_code):
+                if retry.check_http_response_success(error.status_code) == False:
+                    logger.debug("HttpError returned {}, saving error and not retrying.".format(error.status_code))
+                    output_retry_loop.save_result(error)
                 else:
-                    pass
-                    print ok
-                    print error.status_code
-                    ok = True
-            else:
-                output_retry_loop.save_result(result)
-                ok = True
+                    logger.debug("HttpError returned {}, retrying with {} tries left".format(error.status_code,tries_left+1))
+        else:
+            output_retry_loop.save_result(result)
     if output_retry_loop.success():
         return output_retry_loop.last_result()	    
 
 _current_task = None
- at retry_method
-def current_task():
+def current_task(api_client=None):
     global _current_task
+
     if _current_task:
         return _current_task
-    current_task_retry_loop = RetryLoop(num_retries=5, backoff_start=1)
+
+    if not api_client:
+        api_client = api('v1')
+
+    current_task_retry_loop = RetryLoop(num_retries=2, backoff_start=1)
     for tries_left in current_task_retry_loop:
 	try:
-	    t = api('v1').job_tasks().get(uuid=os.environ['TASK_UUID']).execute()
+	    t = api_client.job_tasks().get(uuid=os.environ['TASK_UUID']).execute()
 	except TemporaryError as error:
 	    logger.debug("Error in current_task api call: {} ({} tries left)".format(error,tries_left))
 	else:
@@ -99,8 +96,7 @@ def current_task():
         return t
 
 _current_job = None
- at retry_method
-def current_job(num_retries=5):
+def current_job():
     global _current_job
     if _current_job:
         return _current_job
diff --git a/sdk/python/tests/test_init.py b/sdk/python/tests/test_init.py
index c17f789..bc56ca3 100644
--- a/sdk/python/tests/test_init.py
+++ b/sdk/python/tests/test_init.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+ #!/usr/bin/env python
 
 import mock
 import os
@@ -11,11 +11,18 @@ class TestSDK(unittest.TestCase):
 
     FAKE_HASH = '7idummyhashb0b1f1f03e4e6f69c4a4e+28243'
 
-    def test_task_set_output(self, mock_input=FAKE_HASH):
-        mock_api = mock.MagicMock()
-	mock_api.job_tasks().update().execute.side_effect = arvados.errors.HttpError(status_code=500,reason="Mock 200")
-        arvados.task_set_output({'uuid':'zzzzz-zzzzz-ehnr5qheh1atzzz'},s=mock_input,api_client=mock_api)
+    mock_api = mock.MagicMock()
 
+    def test_task_set_output_success(self, mock_input=FAKE_HASH, api_client=mock_api):
+	api_client.job_tasks().update().execute.side_effect = arvados.errors.HttpError(status_code=200,reason="Mock 200")
+        arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s=mock_input,api_client=api_client)
+        
+    def test_task_set_output_failure(self, mock_input=FAKE_HASH, api_client=mock_api):
+        api_client.job_tasks().update().execute.side_effect = arvados.errors.HttpError(status_code=404,reason="Mock 404")
+        arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s=mock_input,api_client=api_client)
 
+    def test_task_set_output_retryable(self, mock_input=FAKE_HASH, api_client=mock_api):
+        api_client.job_tasks().update().execute.side_effect = arvados.errors.HttpError(status_code=408,reason="Mock 500")
+        arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s=mock_input,api_client=api_client)
 
         # need a spy to make mock_api return down if retry_num = 1 and mock_api return up if retry_num = 2

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list