Skip to content

Commit 17cf714

Browse files
committed
Remove trainings at all fro API
Rather than listing cancelled trainings, lets remove them
1 parent 0e16f91 commit 17cf714

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

deepaas/api/v2/train.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@ def __init__(self, model_name, model_obj):
4242
self.model_obj = model_obj
4343
self._trainings = {}
4444

45-
def build_train_response(self, uuid_):
46-
training = self._trainings.get(uuid_, None)
47-
45+
@staticmethod
46+
def build_train_response(uuid, training):
4847
if not training:
4948
return
5049

5150
ret = {}
5251
ret["date"] = training["date"]
53-
ret["uuid"] = uuid_
52+
ret["uuid"] = uuid
5453

5554
if training["task"].cancelled():
5655
ret["status"] = "cancelled"
@@ -78,7 +77,7 @@ async def post(self, request, args):
7877
"date": str(datetime.datetime.now()),
7978
"task": train_task,
8079
}
81-
ret = self.build_train_response(uuid_)
80+
ret = self.build_train_response(uuid_, self._trainings[uuid_])
8281
return web.json_response(ret)
8382

8483
@aiohttp_apispec.docs(
@@ -87,7 +86,7 @@ async def post(self, request, args):
8786
)
8887
async def delete(self, request):
8988
uuid_ = request.match_info["uuid"]
90-
training = self._trainings.get(uuid_, None)
89+
training = self._trainings.pop(uuid_, None)
9190
if not training:
9291
raise web.HTTPNotFound()
9392
training["task"].cancel()
@@ -96,7 +95,7 @@ async def delete(self, request):
9695
except asyncio.TimeoutError:
9796
pass
9897
LOG.info("Training %s has been cancelled" % uuid_)
99-
ret = self.build_train_response(uuid_)
98+
ret = self.build_train_response(uuid_, training)
10099
return web.json_response(ret)
101100

102101
@aiohttp_apispec.docs(
@@ -107,7 +106,8 @@ async def delete(self, request):
107106
async def index(self, request):
108107
ret = []
109108
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)
111111
ret.append(aux)
112112

113113
return web.json_response(ret)
@@ -119,7 +119,8 @@ async def index(self, request):
119119
@aiohttp_apispec.response_schema(responses.Training(), 200)
120120
async def get(self, request):
121121
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)
123124
if ret:
124125
return web.json_response(ret)
125126
raise web.HTTPNotFound()

0 commit comments

Comments
 (0)