@@ -42,15 +42,14 @@ def __init__(self, model_name, model_obj):
42
42
self .model_obj = model_obj
43
43
self ._trainings = {}
44
44
45
- def build_train_response (self , uuid_ ):
46
- training = self ._trainings .get (uuid_ , None )
47
-
45
+ @staticmethod
46
+ def build_train_response (uuid , training ):
48
47
if not training :
49
48
return
50
49
51
50
ret = {}
52
51
ret ["date" ] = training ["date" ]
53
- ret ["uuid" ] = uuid_
52
+ ret ["uuid" ] = uuid
54
53
55
54
if training ["task" ].cancelled ():
56
55
ret ["status" ] = "cancelled"
@@ -78,7 +77,7 @@ async def post(self, request, args):
78
77
"date" : str (datetime .datetime .now ()),
79
78
"task" : train_task ,
80
79
}
81
- ret = self .build_train_response (uuid_ )
80
+ ret = self .build_train_response (uuid_ , self . _trainings [ uuid_ ] )
82
81
return web .json_response (ret )
83
82
84
83
@aiohttp_apispec .docs (
@@ -87,7 +86,7 @@ async def post(self, request, args):
87
86
)
88
87
async def delete (self , request ):
89
88
uuid_ = request .match_info ["uuid" ]
90
- training = self ._trainings .get (uuid_ , None )
89
+ training = self ._trainings .pop (uuid_ , None )
91
90
if not training :
92
91
raise web .HTTPNotFound ()
93
92
training ["task" ].cancel ()
@@ -96,7 +95,7 @@ async def delete(self, request):
96
95
except asyncio .TimeoutError :
97
96
pass
98
97
LOG .info ("Training %s has been cancelled" % uuid_ )
99
- ret = self .build_train_response (uuid_ )
98
+ ret = self .build_train_response (uuid_ , training )
100
99
return web .json_response (ret )
101
100
102
101
@aiohttp_apispec .docs (
@@ -107,7 +106,8 @@ async def delete(self, request):
107
106
async def index (self , request ):
108
107
ret = []
109
108
for uuid_ , training in self ._trainings .items ():
110
- aux = self .build_train_response (uuid_ )
109
+ training = self ._trainings .get (uuid_ , None )
110
+ aux = self .build_train_response (uuid_ , training )
111
111
ret .append (aux )
112
112
113
113
return web .json_response (ret )
@@ -119,7 +119,8 @@ async def index(self, request):
119
119
@aiohttp_apispec .response_schema (responses .Training (), 200 )
120
120
async def get (self , request ):
121
121
uuid_ = request .match_info ["uuid" ]
122
- ret = self .build_train_response (uuid_ )
122
+ training = self ._trainings .get (uuid_ , None )
123
+ ret = self .build_train_response (uuid_ , training )
123
124
if ret :
124
125
return web .json_response (ret )
125
126
raise web .HTTPNotFound ()
0 commit comments