Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Commit 43354be

Browse files
authored
Merge pull request #864 from helgi/async_restart
feat(app): during ps:restart run pod delete in parallel
2 parents 3de1a52 + 63c8f4d commit 43354be

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

rootfs/api/models/app.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import backoff
23
from collections import OrderedDict
34
from datetime import datetime
@@ -294,9 +295,24 @@ def restart(self, **kwargs): # noqa
294295
return []
295296

296297
try:
297-
for pod in self.list_pods(**kwargs):
298-
# This function verifies the delete
299-
self._scheduler.delete_pod(self.id, pod['name'])
298+
@asyncio.coroutine
299+
def delete_pod(namespace, name, loop):
300+
"""
301+
A synchronous function that deletes a pod
302+
"""
303+
logger.debug('Deleting pod {} as part of a pod restart call'.format(name))
304+
# Gives a pod however long the termination grace period is to terminate
305+
# This executes a delete in its own thread (in parallel)
306+
yield from loop.run_in_executor(None, self._scheduler.delete_pod, namespace, name)
307+
logger.debug('Finished deleting pod {}'.format(name))
308+
309+
# gather all pods to be deleted
310+
loop = asyncio.get_event_loop()
311+
tasks = [delete_pod(self.id, pod['name'], loop) for pod in self.list_pods(**kwargs)]
312+
if tasks:
313+
# run deletes in parallel
314+
loop.run_until_complete(asyncio.wait(tasks))
315+
300316
except Exception as e:
301317
err = "warning, some pods failed to stop:\n{}".format(str(e))
302318
self.log(err, logging.WARNING)

0 commit comments

Comments
 (0)