From dde89d62df842e479e8efbe00b821590ba399798 Mon Sep 17 00:00:00 2001 From: aloftus23 Date: Thu, 12 Dec 2024 18:53:06 -0500 Subject: [PATCH] Move django setup in lambdas --- backend/package.json | 2 +- .../xfd_api/tasks/elasticache_tasks.py | 7 ++++--- .../src/xfd_django/xfd_api/tasks/scheduler.py | 16 ++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/backend/package.json b/backend/package.json index f6cd947d..adddfc4c 100644 --- a/backend/package.json +++ b/backend/package.json @@ -13,7 +13,7 @@ "build-worker": "sh ./tools/build-worker.sh", "codegen": "ts-node src/tools/generate-types.ts", "control-queue": "docker compose exec -T backend npx ts-node src/tools/consumeControlQueue.ts", - "deploy-worker-prod": "./tools/deploy-worker.sh crossfeed-prod-worker", + "deploy-worker-integration": "./tools/deploy-worker.sh crossfeed-integration-worker", "deploy-worker-staging": "./tools/deploy-worker.sh", "lint": "eslint '**/*.{ts,tsx,js,jsx}'", "lint:fix": "eslint '**/*.{ts,tsx,js,jsx}' --fix", diff --git a/backend/src/xfd_django/xfd_api/tasks/elasticache_tasks.py b/backend/src/xfd_django/xfd_api/tasks/elasticache_tasks.py index da41863e..2deab701 100644 --- a/backend/src/xfd_django/xfd_api/tasks/elasticache_tasks.py +++ b/backend/src/xfd_django/xfd_api/tasks/elasticache_tasks.py @@ -8,9 +8,6 @@ from django.db.models import CharField, Count, F, Value from django.db.models.functions import Concat import redis -from xfd_api.helpers.stats_helpers import populate_stats_cache - -from ..models import Service, Vulnerability # Set the Django settings module os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xfd_django.settings") @@ -19,6 +16,10 @@ # Initialize Django django.setup() +# Third-Party Libraries +from xfd_api.helpers.stats_helpers import populate_stats_cache +from xfd_api.models import Service, Vulnerability + def populate_services_cache(): return populate_stats_cache( diff --git a/backend/src/xfd_django/xfd_api/tasks/scheduler.py b/backend/src/xfd_django/xfd_api/tasks/scheduler.py index fdd08ab2..fe5018d6 100644 --- a/backend/src/xfd_django/xfd_api/tasks/scheduler.py +++ b/backend/src/xfd_django/xfd_api/tasks/scheduler.py @@ -6,19 +6,19 @@ import os # Third-Party Libraries +import django from django.utils import timezone -from ..helpers.getScanOrganizations import get_scan_organizations -from ..models import Organization, Scan, ScanTask -from ..schema_models.scan import SCAN_SCHEMA -from .ecs_client import ECSClient - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xfd_django.settings") os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true" -import django -print("Setting up Django...") + django.setup() -print("Django setup complete.") + +# Third-Party Libraries +from xfd_api.helpers.getScanOrganizations import get_scan_organizations +from xfd_api.models import Organization, Scan, ScanTask +from xfd_api.schema_models.scan import SCAN_SCHEMA +from xfd_api.tasks.ecs_client import ECSClient def chunk(iterable, size):