1414
1515
1616log = logging .getLogger (__name__ )
17+ USE_SANDBOX = os .getenv ("BOHRIUM_USE_SANDBOX" ) in ["1" , "true" ]
1718
1819
1920class Job (SyncAPIResource ):
@@ -27,15 +28,15 @@ def create(self, project_id, name='', group_id=0):
2728 if group_id :
2829 data ['bohrGroupId' ] = group_id
2930 try :
30- data = self ._client .post (f'/openapi/v1/job/create' , json = data , params = self ._client .params )
31+ data = self ._client .post (f'/openapi/v1/sandbox/job/create' if USE_SANDBOX else f'/openapi/v1/ job/create' , json = data , params = self ._client .params )
3132 data = data .json ()
3233 except Exception as e :
3334 raise e
3435 return data .get ("data" , {})
3536
3637 def detail (self , job_id ):
3738 log .info (f"detail job { job_id } " )
38- response = self ._client .get (f"/openapi/v1/job/{ job_id } " )
39+ response = self ._client .get (f"/openapi/v1/sandbox/job/ { job_id } " if USE_SANDBOX else f"/openapi/v1/ job/{ job_id } " )
3940
4041 log .info (response .json ())
4142 log .debug (response )
@@ -95,28 +96,29 @@ def insert(self, **kwargs):
9596 camel_data ['logFiles' ] = camel_data ['logFile' ]
9697 if 'logFiles' in camel_data and not isinstance (camel_data ['logFiles' ], list ):
9798 camel_data ['logFiles' ] = [camel_data ['logFiles' ]]
98- response = self ._client .post ("/openapi/v2/job/add" , json = camel_data )
99+ response = self ._client .post ("/openapi/v1/sandbox/job/add" if USE_SANDBOX else "/openapi/v2/job/add" , json = camel_data )
100+ log .info (f'[insert] json={ camel_data } , response={ response .json ()} ' )
99101 return response .json ().get ("data" )
100102
101103 def delete (self , job_id ):
102104 # log.info(f"delete job {job_id}")
103- response = self ._client .post (f"/openapi/v1/job/del/{ job_id } " )
105+ response = self ._client .post (f"/openapi/v1/sandbox/job/del/ { job_id } " if USE_SANDBOX else f"/openapi/v1/ job/del/{ job_id } " )
104106
105107
106108 def terminate (self , job_id ):
107109 # log.info(f"terminate job {job_id}")
108- response = self ._client .post (f"/openapi/v1/job/terminate/{ job_id } " )
110+ response = self ._client .post (f"/openapi/v1/sandbox/job/terminate/ { job_id } " if USE_SANDBOX else f"/openapi/v1/ job/terminate/{ job_id } " )
109111
110112
111113 def kill (self , job_id ):
112114 # log.info(f"kill job {job_id}")
113- response = self ._client .post (f"/openapi/v1/job/kill/{ job_id } " )
115+ response = self ._client .post (f"/openapi/v1/sandbox/job/kill/ { job_id } " if USE_SANDBOX else f"/openapi/v1/ job/kill/{ job_id } " )
114116
115117
116118 def log (self , job_id , log_file = "STDOUTERR" , page = - 1 , page_size = 8192 ):
117119 # log.info(f"log job {job_id}")
118120 response = self ._client .get (
119- f"/openapi/v1/job/{ job_id } /log" ,
121+ f"/openapi/v1/sandbox/job/ { job_id } /log" if USE_SANDBOX else f"/openapi/v1/ job/{ job_id } /log" ,
120122 params = {"logFile" : log_file , "page" : page , "pageSize" : page_size },
121123 )
122124
@@ -146,7 +148,7 @@ def create_job(
146148 "name" : name ,
147149 "bohrGroupId" : group_id ,
148150 }
149- response = self ._client .post (f"/openapi/v1/job/create" , json = data )
151+ response = self ._client .post (f"/openapi/v1/sandbox/job/create" if USE_SANDBOX else f"/openapi/v1/ job/create" , json = data )
150152
151153 return response .json ().get ("data" )
152154
0 commit comments