[PATCH] toaster: Added validation to stop import if there is a build in progress
Marlon Rodriguez Garcia <[email protected]> Thu, 14 Dec 2023 14:44:09 -0500
| Newsgroups | org.yoctoproject.lists.toaster,org.openembedded.lists.bitbake-devel |
|---|---|
| Message-ID | <20231214194409.16525-1-marlon.rodriguez-garcia@savoirfairelinux.com> |
Added validation to prevent simultaneous imports from running because the=
database fails at runtime.
The option to create a queue was taken into consideration. However, it wi=
ll require the use of Celery https://pypi.org/project/celery/ or Backgrou=
nd Task https://pypi.org/project/django-background-tasks/ which require t=
he use of external services and multiple dependencies.
If required we could explore the alternative in the future.
Signed-off-by: Marlon Rodriguez Garcia <marlon.rodriguez-garcia@savoirfai=
relinux.com>
---
lib/toaster/toastergui/templates/command_line_builds.html | 6 +++++-
lib/toaster/toastergui/views.py | 8 ++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/lib/toaster/toastergui/templates/command_line_builds.html b/=
lib/toaster/toastergui/templates/command_line_builds.html
index fcbe80d8..05db6727 100644
--- a/lib/toaster/toastergui/templates/command_line_builds.html
+++ b/lib/toaster/toastergui/templates/command_line_builds.html
@@ -152,7 +152,11 @@ function _ajax_update(file, all, dir){
type: "POST",
data: {file: file, all: all, dir: dir},
success:function(data){
- window.location =3D '/toastergui/builds/'
+ if (data['response']=3D=3D'building'){
+ location.reload()
+ } else {
+ window.location =3D '/toastergui/builds/'
+ }
},
complete:function(data){
},
diff --git a/lib/toaster/toastergui/views.py b/lib/toaster/toastergui/vie=
ws.py
index 3b5b9f5b..40aed265 100644
--- a/lib/toaster/toastergui/views.py
+++ b/lib/toaster/toastergui/views.py
@@ -2018,6 +2018,14 @@ class CommandLineBuilds(TemplateView):
logs_dir =3D request.POST.get('dir')
all_files =3D request.POST.get('all')
=20
+ # check if a build is already in progress
+ if Build.objects.filter(outcome=3DBuild.IN_PROGRESS):
+ messages.add_message(
+ self.request,
+ messages.ERROR,
+ "A build is already in progress. Please wait for it to c=
omplete before starting a new build."
+ )
+ return JsonResponse({'response': 'building'})
imported_files =3D EventLogsImports.objects.all()
try:
if all_files =3D=3D 'true':
--=20
2.34.1