Browse Source

perf: add host deployment task

pull/9075/head
Eric 2 years ago
parent
commit
ef637e91b9
  1. 2
      apps/terminal/api/applet/host.py
  2. 18
      apps/terminal/migrations/0059_applethostdeployment_task.py
  3. 5
      apps/terminal/models/applet/host.py
  4. 2
      apps/terminal/serializers/applet_host.py

2
apps/terminal/api/applet/host.py

@ -49,6 +49,7 @@ class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
serializer.is_valid(raise_exception=True)
instance = serializer.save()
task = run_applet_host_deployment.delay(instance.id)
instance.save_task(task.id)
return Response({'task': str(task.id)}, status=201)
@action(methods=['post'], detail=False, serializer_class=AppletHostDeployAppletSerializer)
@ -58,4 +59,5 @@ class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
applet_id = serializer.validated_data.get('applet_id')
instance = serializer.save()
task = run_applet_host_deployment_install_applet.delay(instance.id, applet_id)
instance.save_task(task.id)
return Response({'task': str(task.id)}, status=201)

18
apps/terminal/migrations/0059_applethostdeployment_task.py

@ -0,0 +1,18 @@
# Generated by Django 3.2.14 on 2022-11-15 05:53
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('terminal', '0058_auto_20221103_1624'),
]
operations = [
migrations.AddField(
model_name='applethostdeployment',
name='task',
field=models.UUIDField(null=True, verbose_name='Task'),
),
]

5
apps/terminal/models/applet/host.py

@ -105,6 +105,7 @@ class AppletHostDeployment(JMSBaseModel):
date_start = models.DateTimeField(null=True, verbose_name=_('Date start'), db_index=True)
date_finished = models.DateTimeField(null=True, verbose_name=_("Date finished"))
comment = models.TextField(default='', blank=True, verbose_name=_('Comment'))
task = models.UUIDField(null=True, verbose_name=_('Task'))
def start(self, **kwargs):
from ...automations.deploy_applet_host import DeployAppletHostManager
@ -120,3 +121,7 @@ class AppletHostDeployment(JMSBaseModel):
applet = None
manager = DeployAppletHostManager(self, applet=applet)
manager.install_applet(**kwargs)
def save_task(self, task):
self.task = task
self.save(update_fields=['task'])

2
apps/terminal/serializers/applet_host.py

@ -86,7 +86,7 @@ class HostAppletSerializer(AppletSerializer):
class AppletHostDeploymentSerializer(serializers.ModelSerializer):
class Meta:
model = AppletHostDeployment
fields_mini = ['id', 'host', 'status']
fields_mini = ['id', 'host', 'status', 'task']
read_only_fields = [
'status', 'date_created', 'date_updated',
'date_start', 'date_finished'

Loading…
Cancel
Save