Skip to content

Commit

Permalink
Move django setup in lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
aloftus23 committed Dec 12, 2024
1 parent be1c42d commit dde89d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions backend/src/xfd_django/xfd_api/tasks/elasticache_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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(
Expand Down
16 changes: 8 additions & 8 deletions backend/src/xfd_django/xfd_api/tasks/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit dde89d6

Please sign in to comment.