This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git


The following commit(s) were added to refs/heads/master by this push:
     new 5682b69  [test] fix cancel task tests (#614)
5682b69 is described below

commit 5682b6970800e676127e03d96083b6112c29044a
Author: Qinkun Bao <[email protected]>
AuthorDate: Mon Feb 7 14:28:30 2022 -0800

    [test] fix cancel task tests (#614)
---
 examples/python/mesapy_deadloop_cancel.py | 12 +++++++++---
 sdk/python/teaclave.py                    | 12 ++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/examples/python/mesapy_deadloop_cancel.py 
b/examples/python/mesapy_deadloop_cancel.py
index b3c014a..2bd7206 100644
--- a/examples/python/mesapy_deadloop_cancel.py
+++ b/examples/python/mesapy_deadloop_cancel.py
@@ -20,7 +20,7 @@
 import sys
 import time
 
-from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap
+from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap, 
TaskStatus
 from utils import USER_ID, USER_PASSWORD, connect_authentication_service, 
connect_frontend_service, PlatformAdmin
 
 
@@ -58,8 +58,14 @@ class MesaPyEchoExample:
         print("[+] invoking task")
         client.invoke_task(task_id)
 
+        print("[+] waiting task")
+        while True:
+            task = client.get_task(task_id)
+            time.sleep(5)
+            if task['status'] == TaskStatus.Running:
+                break
+
         print("[+] canceling task")
-        time.sleep(5)
         client.cancel_task(task_id)
 
         time.sleep(5)
@@ -67,7 +73,7 @@ class MesaPyEchoExample:
         print("[+] getting result")
 
         result = client.get_task(task_id)
-        if result["status"] != 20:
+        if result["status"] != TaskStatus.Canceled:
             print("[+] Task is not canceled, cancel again")
             client.cancel_task(task_id)
 
diff --git a/sdk/python/teaclave.py b/sdk/python/teaclave.py
index 39b650e..88080f3 100644
--- a/sdk/python/teaclave.py
+++ b/sdk/python/teaclave.py
@@ -33,6 +33,7 @@ import ssl
 import socket
 
 from typing import Tuple, Dict, List, Any
+from enum import IntEnum
 
 import cryptography
 from cryptography import x509
@@ -50,6 +51,17 @@ __all__ = [
 Metadata = Dict[str, str]
 
 
+class TaskStatus(IntEnum):
+    Created = 0
+    DataAssigned = 1
+    Approved = 2
+    Staged = 3
+    Running = 4
+    Finished = 10
+    Canceled = 20
+    Failed = 99
+
+
 class Request:
     pass
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to