@@ -29,44 +29,45 @@ async def handle_post_cmd(self, request):
29
29
ten_env = self .ten_env
30
30
31
31
try :
32
- cmd_name = request .match_info .get (' cmd_name' )
32
+ cmd_name = request .match_info .get (" cmd_name" )
33
33
34
34
req_json = await request .json ()
35
35
input_json = json .dumps (req_json , ensure_ascii = False )
36
36
37
37
ten_env .log_debug (
38
- f"process incoming request { request .method } { request .path } { input_json } " )
38
+ f"process incoming request { request .method } { request .path } { input_json } "
39
+ )
39
40
40
41
cmd = Cmd .create (cmd_name )
41
42
cmd .set_property_from_json ("" , input_json )
42
43
[cmd_result , _ ] = await asyncio .wait_for (ten_env .send_cmd (cmd ), 5.0 )
43
44
44
45
# return response
45
46
status = 200 if cmd_result .get_status_code () == StatusCode .OK else 502
46
- return web .json_response (
47
- cmd_result .get_property_to_json ("" ), status = status
48
- )
47
+ return web .json_response (cmd_result .get_property_to_json ("" ), status = status )
49
48
except json .JSONDecodeError :
50
49
return web .Response (status = 400 )
51
50
except asyncio .TimeoutError :
52
51
return web .Response (status = 504 )
53
52
except Exception as e :
54
53
ten_env .log_warn (
55
- "failed to handle request with unknown exception, err {}" .format (e ))
54
+ "failed to handle request with unknown exception, err {}" .format (e )
55
+ )
56
56
return web .Response (status = 500 )
57
57
58
58
# POST /data/{data_name}
59
59
async def handle_post_data (self , request ):
60
60
ten_env = self .ten_env
61
61
62
62
try :
63
- data_name = request .match_info .get (' data_name' )
63
+ data_name = request .match_info .get (" data_name" )
64
64
65
65
req_json = await request .json ()
66
66
input_json = json .dumps (req_json , ensure_ascii = False )
67
67
68
68
ten_env .log_debug (
69
- f"process incoming request { request .method } { request .path } { input_json } " )
69
+ f"process incoming request { request .method } { request .path } { input_json } "
70
+ )
70
71
71
72
data = Data .create (data_name )
72
73
data .set_property_from_json ("" , input_json )
@@ -78,7 +79,8 @@ async def handle_post_data(self, request):
78
79
return web .Response (status = 400 )
79
80
except Exception as e :
80
81
ten_env .log_warn (
81
- "failed to handle request with unknown exception, err {}" .format (e ))
82
+ "failed to handle request with unknown exception, err {}" .format (e )
83
+ )
82
84
return web .Response (status = 500 )
83
85
84
86
async def on_start (self , async_ten_env : AsyncTenEnv ):
@@ -89,7 +91,8 @@ async def on_start(self, async_ten_env: AsyncTenEnv):
89
91
self .ten_env = async_ten_env
90
92
91
93
async_ten_env .log_info (
92
- f"http server listening on { self .listen_addr } :{ self .listen_port } " )
94
+ f"http server listening on { self .listen_addr } :{ self .listen_port } "
95
+ )
93
96
94
97
self .app .router .add_post ("/cmd/{cmd_name}" , self .handle_post_cmd )
95
98
self .app .router .add_post ("/data/{data_name}" , self .handle_post_data )
0 commit comments