Skip to content

Commit

Permalink
Add django.setup to scheduler lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
aloftus23 committed Dec 10, 2024
1 parent 2fa929a commit dbf4ae8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion backend/src/xfd_django/xfd_api/api_methods/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ def run_scan(scan_id: str, current_user):

scan.manualRunPending = True
scan.save()
return {"status": "success", "message": f"Scan {scan_id} set to manualRunPending."}
return {
"status": "success",
"message": f"Scan {scan_id} set to manualRunPending.",
}

except HTTPException as http_exc:
raise http_exc
Expand Down
2 changes: 1 addition & 1 deletion backend/src/xfd_django/xfd_api/api_methods/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def search(search_body: SearchBody, event) -> Dict[str, Any]:

def search_post(request_input):
"""Handle Elastic Search request"""

es_query = build_elasticsearch_query(request_input)

# Perform search in Elasticsearch TODO: Confirm index name and format
Expand Down
8 changes: 8 additions & 0 deletions backend/src/xfd_django/xfd_api/tasks/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
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

# Set the Django settings module
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xfd_django.settings")
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"

# Initialize Django
django.setup()


def chunk(iterable, size):
"""Chunk a list into a nested list."""
Expand Down

0 comments on commit dbf4ae8

Please sign in to comment.