Skip to content

Commit 3a2aadf

Browse files
committed
feat(controller): multi pod restart uses async
1 parent abdd796 commit 3a2aadf

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

rootfs/api/models/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,6 @@ def verify_application_health(self, **kwargs):
697697
only run after kubernetes has reported all pods as healthy
698698
"""
699699
# Bail out early if the application is not routable
700-
release = self.release_set.filter(failed=False).latest()
701700
app_settings = self.appsettings_set.latest()
702701
if not kwargs.get('routable', False) and app_settings.routable:
703702
return

rootfs/api/settings/celery.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class Config:
2626
app.config_from_object(Config)
2727
app.conf.update(
2828
task_routes={
29+
'api.tasks.scale_app': {'queue': 'priority.high'},
30+
'api.tasks.restart_app': {'queue': 'priority.high'},
2931
'api.tasks.retrieve_resource': {'queue': 'priority.high'},
3032
},
3133
)

rootfs/api/tasks.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,17 @@ def scale_app(app, user, structure):
6161
app.scale(user, structure)
6262
finally:
6363
signals.request_finished.send(sender=task_id)
64+
65+
66+
@shared_task(
67+
autoretry_for=(ServiceUnavailable, ),
68+
retry_jitter=True,
69+
retry_kwargs={'max_retries': 3}
70+
)
71+
def restart_app(app, **kwargs):
72+
task_id = uuid.uuid4().hex
73+
signals.request_started.send(sender=task_id)
74+
try:
75+
app.restart(**kwargs)
76+
finally:
77+
signals.request_finished.send(sender=task_id)

rootfs/api/views.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from rest_framework.viewsets import GenericViewSet
2121

2222
from api import influxdb, models, permissions, serializers, viewsets
23-
from api.tasks import scale_app
23+
from api.tasks import scale_app, restart_app
2424
from api.models import AlreadyExists, ServiceUnavailable, DryccException, \
2525
UnprocessableEntity
2626

@@ -280,7 +280,11 @@ def list(self, *args, **kwargs):
280280
return Response(pagination, status=status.HTTP_200_OK)
281281

282282
def restart(self, *args, **kwargs):
283-
pods = self.get_app().restart(**kwargs)
283+
if "name" in kwargs: # a single pod uses sync
284+
pods = self.get_app().restart(**kwargs)
285+
else: # multi pod uses async
286+
restart_app.delay(self.get_app(), **kwargs)
287+
pods = self.get_app().list_pods(**kwargs)
284288
data = self.get_serializer(pods, many=True).data
285289
# fake out pagination for now
286290
# pagination = {'results': data, 'count': len(data)}

0 commit comments

Comments
 (0)