From 602a59bd84bb4e84da9f87971d119b97d3cecb0e Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Fri, 4 Jul 2025 03:00:51 +0300 Subject: [PATCH] Features: 1) Add exit condition checks for `$LASTEXITCODE` in various PowerShell scripts to ensure graceful error handling; 2) Enhance schema filtering with additional condition for active vendors in `graphene/schema.py`; Fixes: 1) Remove unused imports in `celery.py`; Extra: Refactor formatting and improve code readability in PowerShell scripts. --- core/graphene/schema.py | 6 +++++- evibes/celery.py | 2 -- scripts/Windows/backup.ps1 | 9 ++++++++ scripts/Windows/export-environment-file.ps1 | 3 +++ scripts/Windows/generate-environment-file.ps1 | 3 +++ scripts/Windows/reboot.ps1 | 21 +++++++++++++++++++ scripts/Windows/run.ps1 | 18 ++++++++++++++++ scripts/Windows/uninstall.ps1 | 15 +++++++++++++ 8 files changed, 74 insertions(+), 3 deletions(-) diff --git a/core/graphene/schema.py b/core/graphene/schema.py index c38a8b80..13585ef0 100644 --- a/core/graphene/schema.py +++ b/core/graphene/schema.py @@ -145,7 +145,11 @@ class Query(ObjectType): Product.objects.all().select_related("brand", "category").prefetch_related("images", "stocks") if info.context.user.has_perm("core.view_product") else Product.objects.filter( - is_active=True, brand__is_active=True, category__is_active=True, stocks__isnull=False + is_active=True, + brand__is_active=True, + category__is_active=True, + stocks__isnull=False, + stocks__vendor__is_active=True, ) .select_related("brand", "category") .prefetch_related("images", "stocks") diff --git a/evibes/celery.py b/evibes/celery.py index 421530d4..5ddabb48 100644 --- a/evibes/celery.py +++ b/evibes/celery.py @@ -2,8 +2,6 @@ import os from celery import Celery -from evibes.settings import REDIS_PASSWORD, TIME_ZONE - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "evibes.settings") app = Celery("evibes") diff --git a/scripts/Windows/backup.ps1 b/scripts/Windows/backup.ps1 index cc12a11b..bf890dd7 100644 --- a/scripts/Windows/backup.ps1 +++ b/scripts/Windows/backup.ps1 @@ -3,11 +3,20 @@ Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' .\scripts\Windows\starter.ps1 +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Starting database backup process..." -ForegroundColor Magenta docker compose exec app poetry run python manage.py dbbackup +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Database backup created under ./dbbackup" -ForegroundColor Green Write-Host "Starting media backup process..." -ForegroundColor Magenta docker compose exec app poetry run python manage.py mediabackup +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Media backup created under ./dbbackup" -ForegroundColor Green \ No newline at end of file diff --git a/scripts/Windows/export-environment-file.ps1 b/scripts/Windows/export-environment-file.ps1 index 010d44b0..402cba9e 100644 --- a/scripts/Windows/export-environment-file.ps1 +++ b/scripts/Windows/export-environment-file.ps1 @@ -3,6 +3,9 @@ Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' .\scripts\Windows\starter.ps1 +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} $envFile = '.env' diff --git a/scripts/Windows/generate-environment-file.ps1 b/scripts/Windows/generate-environment-file.ps1 index 6f0d1db5..d76182cc 100644 --- a/scripts/Windows/generate-environment-file.ps1 +++ b/scripts/Windows/generate-environment-file.ps1 @@ -2,6 +2,9 @@ Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' .\scripts\Windows\starter.ps1 +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} function Get-RandomHex { diff --git a/scripts/Windows/reboot.ps1 b/scripts/Windows/reboot.ps1 index 60d79b8d..ec0e2f2c 100644 --- a/scripts/Windows/reboot.ps1 +++ b/scripts/Windows/reboot.ps1 @@ -2,30 +2,51 @@ Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' .\scripts\Windows\starter.ps1 +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Shutting down..." -ForegroundColor Magenta docker compose down +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Services were shut down successfully!" -ForegroundColor Green Write-Host "Spinning services up..." -ForegroundColor Magenta docker compose up -d --build --wait +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Services are up and healthy!" -ForegroundColor Green Write-Host "Applying migrations..." -ForegroundColor Magenta docker compose exec app poetry run python manage.py migrate --no-input --verbosity 0 +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Migrations applied successfully!" -ForegroundColor Green Write-Host "Collecting static files..." -ForegroundColor Magenta docker compose exec app poetry run python manage.py collectstatic --clear --no-input --verbosity 0 +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Static files collected successfully!" -ForegroundColor Green Write-Host "Setting default caches..." -ForegroundColor Magenta docker compose exec app poetry run python manage.py set_default_caches +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Default caches set successfully!" -ForegroundColor Green Write-Host "Cleaning up unused Docker data..." -ForegroundColor Magenta docker system prune -f +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Unused Docker data cleaned successfully!" -ForegroundColor Green Write-Host "All done! eVibes is up and running!" -ForegroundColor Cyan diff --git a/scripts/Windows/run.ps1 b/scripts/Windows/run.ps1 index baadacc6..38f756aa 100644 --- a/scripts/Windows/run.ps1 +++ b/scripts/Windows/run.ps1 @@ -2,6 +2,9 @@ Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' .\scripts\Windows\starter.ps1 +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Verifying all images are present…" -ForegroundColor Green @@ -29,22 +32,37 @@ foreach ($prop in $config.services.PSObject.Properties) Write-Host "Spinning services up..." -ForegroundColor Magenta docker compose up --no-build --detach --wait +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Services are up and healthy!" -ForegroundColor Green Write-Host "Applying migrations..." -ForegroundColor Magenta docker compose exec app poetry run python manage.py migrate --no-input +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Migrations applied successfully!" -ForegroundColor Green Write-Host "Collecting static files..." -ForegroundColor Magenta docker compose exec app poetry run python manage.py collectstatic --clear --no-input +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Static files collected successfully!" -ForegroundColor Green Write-Host "Setting default caches..." -ForegroundColor Magenta docker compose exec app poetry run python manage.py set_default_caches +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Default caches set successfully!" -ForegroundColor Green Write-Host "Cleaning unused Docker data..." -ForegroundColor Magenta docker system prune -f +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Unused Docker data cleaned successfully!" -ForegroundColor Green Write-Host "All done! eVibes is up and running!" -ForegroundColor Cyan diff --git a/scripts/Windows/uninstall.ps1 b/scripts/Windows/uninstall.ps1 index bee7d3a4..2ef36b9f 100644 --- a/scripts/Windows/uninstall.ps1 +++ b/scripts/Windows/uninstall.ps1 @@ -2,18 +2,33 @@ Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' .\scripts\Windows\starter.ps1 +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Shutting down..." -ForegroundColor Magenta docker compose down +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Services were shut down successfully!" -ForegroundColor Green Write-Host "Removing volumes..." -ForegroundColor Magenta docker volume remove -f evibes_prometheus-data +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} docker volume remove -f evibes_es-data +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Volumes were removed successfully!" -ForegroundColor Green Write-Host "Cleaning up unused Docker data..." -ForegroundColor Magenta docker system prune -a -f --volumes +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} Write-Host "Unused Docker data cleaned successfully!" -ForegroundColor Green Write-Host "Removing related files..." -ForegroundColor Magenta