perf: add host deployment task

pull/9075/head
Eric 2 years ago
parent 9d0e2b2872
commit ef637e91b9

@ -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)

@ -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'),
),
]

@ -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'])

@ -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