applications: run deploy in async job (#69655)

This commit is contained in:
Lauréline Guérin 2022-10-31 15:39:06 +01:00
parent 7d7d35372d
commit 92aeb41e55
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 16 additions and 2 deletions

View File

@ -19,6 +19,7 @@ import json
import os
import sys
import tarfile
import traceback
import urllib.parse
from django.conf import settings
@ -278,7 +279,9 @@ class AsyncJob(models.Model):
self.application.scandeps()
elif self.action == 'create_bundle':
self.version.create_bundle()
except Exception as e:
elif self.action == 'deploy':
self.version.deploy()
except Exception:
if self.raise_exception:
raise
self.status = 'failed'

View File

@ -323,7 +323,18 @@ class Install(FormView):
version.bundle.save('%s.tar' % app.slug, content=ContentFile(tar_io.getvalue()))
version.save()
version.deploy()
job = AsyncJob(
label=_('Deploying application bundle'),
application=app,
version=version,
action='deploy',
)
job.save()
job.run(spool=True)
if job.status == 'registered':
return HttpResponseRedirect(
reverse('application-async-job', kwargs={'app_slug': app.slug, 'pk': job.id})
)
return super().form_valid(form)