From f9365b3e37f80d0d28698dccb148ee0db141b2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E4=BA=8C=E7=8C=9B?= Date: Sat, 21 Dec 2019 12:36:40 +0800 Subject: [PATCH] A api update --- spug_api/apps/deploy/urls.py | 2 +- spug_api/apps/deploy/views.py | 38 +++++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/spug_api/apps/deploy/urls.py b/spug_api/apps/deploy/urls.py index b1ee298..dafba11 100644 --- a/spug_api/apps/deploy/urls.py +++ b/spug_api/apps/deploy/urls.py @@ -4,5 +4,5 @@ from .views import * urlpatterns = [ path('request/', RequestView.as_view()), - path('request//', do_deploy), + path('request//', RequestDetailView.as_view()), ] diff --git a/spug_api/apps/deploy/views.py b/spug_api/apps/deploy/views.py index c43d27b..238b802 100644 --- a/spug_api/apps/deploy/views.py +++ b/spug_api/apps/deploy/views.py @@ -58,16 +58,28 @@ class RequestView(View): return json_response(error=error) -def do_deploy(request, r_id): - req = DeployRequest.objects.filter(pk=r_id).first() - if not req: - return json_response(error='未找到指定发布申请') - if req.status != '2': - return json_response(error='该申请单当前状态还不能执行发布') - hosts = Host.objects.filter(id__in=json.loads(req.host_ids)) - token = uuid.uuid4().hex - Thread(target=deploy_dispatch, args=(request, req, token)).start() - outputs = {str(x.id): {'data': ''} for x in hosts} - outputs.update(local={'data': f'{human_time()} 建立接连... '}) - targets = [{'id': x.id, 'title': f'{x.name}({x.hostname}:{x.port})'} for x in hosts] - return json_response({'token': token, 'outputs': outputs, 'targets': targets}) +class RequestDetailView(View): + def get(self, request, r_id): + req = DeployRequest.objects.filter(pk=r_id).first() + if not req: + return json_response(error='为找到指定发布申请') + return json_response({ + 'app_name': req.app.name, + 'env_name': req.app.env.name, + 'status': req.status, + 'status_alias': req.get_status_display() + }) + + def post(self, request, r_id): + req = DeployRequest.objects.filter(pk=r_id).first() + if not req: + return json_response(error='未找到指定发布申请') + if req.status != '2': + return json_response(error='该申请单当前状态还不能执行发布') + hosts = Host.objects.filter(id__in=json.loads(req.host_ids)) + token = uuid.uuid4().hex + Thread(target=deploy_dispatch, args=(request, req, token)).start() + outputs = {str(x.id): {'data': ''} for x in hosts} + outputs.update(local={'data': f'{human_time()} 建立接连... '}) + targets = [{'id': x.id, 'title': f'{x.name}({x.hostname}:{x.port})'} for x in hosts] + return json_response({'token': token, 'outputs': outputs, 'targets': targets})