@@ -48,6 +48,7 @@ def main():
48
48
"port" : s .getsockname ()[1 ],
49
49
}
50
50
send_configuration (config )
51
+ abs_working_dir = os .getcwd ()
51
52
while True :
52
53
s .listen ()
53
54
conn , addr = s .accept ()
@@ -72,7 +73,7 @@ def main():
72
73
event = json .loads (event_str )
73
74
# see if the user specified an execution method
74
75
exec_method = event .get ("remote_task_exec_method" , None )
75
- os .chdir (f" t.{ task_id } " )
76
+ os .chdir (os . path . join ( abs_working_dir , f' t.{ task_id } ' ) )
76
77
if exec_method == "direct" :
77
78
response = json .dumps (globals ()[function_name ](event )).encode ("utf-8" )
78
79
else :
@@ -102,8 +103,20 @@ def main():
102
103
conn .sendall (size_msg .encode ('utf-8' ))
103
104
# send response
104
105
conn .sendall (response )
105
- os .chdir (".." )
106
106
break
107
107
except Exception as e :
108
108
print ("Network function encountered exception " , str (e ), file = sys .stderr )
109
+ response = {
110
+ 'Result' : f'network function encountered exception { e } ' ,
111
+ 'Status Code' : 500
112
+ }
113
+ response = json .dumps (response ).encode ('utf-8' )
114
+ response_size = len (response )
115
+ size_msg = "{}\n " .format (response_size )
116
+ # send the size of response
117
+ conn .sendall (size_msg .encode ('utf-8' ))
118
+ # send response
119
+ conn .sendall (response )
120
+ finally :
121
+ os .chdir (abs_working_dir )
109
122
return 0
0 commit comments