Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ for a list of environment variables that you'll need to populate for your deploy
- `DJANGO_CELERY_BROKER_URL` is used to make sure django can send tasks to the `celery` service.
For example, if using [RabbitMQ](https://www.rabbitmq.com/), it might look like this: `amqp://rabbitmq:5672`
- `AWS_*` and `DJANGO_STORAGE_BUCKET_NAME` are used to make sure the application can connect to your S3 bucket
- `NABAT_API_URL`: the location of the NABat GraphQL endpoint used to retrieve information about files in NABat.
- `DJANGO_BATAI_NABAT_API_URL` (optional): the location of the NABat GraphQL endpoint used to
retrieve information about files in NABat.
- `VITE_APP_API_ROUTE`: this tells the Vue application where the backend (Django) API can be found.
- `DJANGO_BATAI_URL_PATH`: this allows the Django application to be mounted at a subpath in a URL.
It is used by the Django application itself and the nginx configuration at nginx.subpath.template
5 changes: 2 additions & 3 deletions bats_ai/core/tasks/nabat/nabat_data_retrieval.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import logging
import os

from django.conf import settings
from django.contrib.gis.geos import Point
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.db import transaction
Expand All @@ -18,7 +18,6 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('NABatDataRetrieval')

BASE_URL = os.environ.get('NABAT_API_URL', 'https://api.sciencebase.gov/nabat-graphql/graphql')
SOFTWARE_ID = 81
QUERY = """
query fetchAcousticAndSurveyEventInfo {
Expand Down Expand Up @@ -124,7 +123,7 @@ def nabat_recording_initialize(self, recording_id: int, survey_event_id: int, ap
)
try:
response = requests.post(
BASE_URL,
settings.BATAI_NABAT_API_URL,
json={'query': batch_query},
headers=headers,
)
Expand Down
5 changes: 2 additions & 3 deletions bats_ai/core/tasks/nabat/nabat_update_species.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import os

from django.conf import settings
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
import requests

Expand All @@ -11,7 +11,6 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('NABatGetSpecies')

BASE_URL = os.environ.get('NABAT_API_URL', 'https://api.sciencebase.gov/nabat-graphql/graphql')
QUERY = """
query GetAllSpeciesOptions {
allSpecies {
Expand Down Expand Up @@ -75,7 +74,7 @@ def update_nabat_species(self):
processing_task.save()

try:
response = requests.post(BASE_URL, json={'query': QUERY})
response = requests.post(settings.BATAI_NABAT_API_URL, json={'query': QUERY})
response.raise_for_status()
except Exception as e:
processing_task.status = ProcessingTask.Status.ERROR
Expand Down
15 changes: 10 additions & 5 deletions bats_ai/core/views/nabat/nabat_recording.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import base64
import json
import logging
import os

from django.conf import settings
from django.db import transaction
from django.db.models import Q
from django.http import HttpRequest, JsonResponse
Expand Down Expand Up @@ -39,7 +39,6 @@ def admin_auth(request):


SOFTWARE_ID = 81
BASE_URL = os.environ.get('NABAT_API_URL', 'https://api.sciencebase.gov/nabat-graphql/graphql')
QUERY = """
query fetchAcousticAndSurveyEventInfo {
presignedUrlFromAcousticFile(acousticFileId: "%(acoustic_file_id)s") {
Expand Down Expand Up @@ -128,7 +127,9 @@ def get_email_if_authorized(
headers = {'Authorization': f'Bearer {api_token}', 'Content-Type': 'application/json'}
query = QUERY % {'acoustic_file_id': recording_id}
try:
response = requests.post(BASE_URL, json={'query': query}, headers=headers)
response = requests.post(
settings.BATAI_NABAT_API_URL, json={'query': query}, headers=headers
)
except Exception as e:
logger.error(f'API request error: {e}')
return JsonResponse({'error': 'Failed to connect to NABat API'}, status=500)
Expand Down Expand Up @@ -184,7 +185,9 @@ def update_nabat_species(species_id: int, api_token: str, recording_id: int, sur
'species_id': species_id,
}
try:
response = requests.post(BASE_URL, json={'query': batch_query}, headers=headers)
response = requests.post(
settings.BATAI_NABAT_API_URL, json={'query': batch_query}, headers=headers
)
json_response = response.json()
if json_response.get('errors'):
logger.error(f'API Error: {json_response["errors"]}')
Expand Down Expand Up @@ -241,7 +244,9 @@ def generate_nabat_recording(
'acoustic_file_id': recording_id,
}
try:
response = requests.post(BASE_URL, json={'query': batch_query}, headers=headers)
response = requests.post(
settings.BATAI_NABAT_API_URL, json={'query': batch_query}, headers=headers
)
logger.info(response.json())
except Exception:
return JsonResponse(response.json(), status=500)
Expand Down
4 changes: 4 additions & 0 deletions bats_ai/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
# Can be set to mount all URLs at a subpath
BATAI_URL_PATH: str = env.str('DJANGO_BATAI_URL_PATH', default='').strip('/')

BATAI_NABAT_API_URL: str = env.str(
'DJANGO_BATAI_NABAT_API_URL', default='https://api.sciencebase.gov/nabat-graphql/graphql'
)

# Django's docs suggest that STATIC_URL should be a relative path,
# for convenience serving a site on a subpath.
STATIC_URL = f'/{BATAI_URL_PATH}/static/' if BATAI_URL_PATH else '/static/'
Expand Down
1 change: 0 additions & 1 deletion dev/.env.docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ DJANGO_INTERNAL_IPS=0.0.0.0/0

SERVERHOSTNAME=localhost

NABAT_API_URL=https://api.sciencebase.gov/nabat-graphql/graphql
VITE_APP_API_ROOT=http://localhost:8000
VITE_APP_LOGIN_REDIRECT=http://localhost:3000
1 change: 0 additions & 1 deletion dev/.env.docker-compose-native
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ DJANGO_MINIO_STORAGE_URL=http://minioAccessKey:minioSecretKey@localhost:9000/dja

SERVERHOSTNAME=localhost

NABAT_API_URL=https://api.sciencebase.gov/nabat-graphql/graphql
VITE_APP_API_ROOT=http://localhost:8000
VITE_APP_LOGIN_REDIRECT=http://localhost:3000
1 change: 0 additions & 1 deletion prod/.env.kitware-production.template
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ DJANGO_DEFAULT_FROM_EMAIL
SERVERHOSTNAME=batdetectai.kitware.com

# Client
NABAT_API_URL=https://api.sciencebase.gov/nabat-graphql/graphql
VITE_APP_API_ROOT=https://batdetectai.kitware.com
VITE_APP_LOGIN_REDIRECT=https://batdetectai.kitware.com

Expand Down
1 change: 0 additions & 1 deletion prod/.env.nabat-production.template
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ DJANGO_BATAI_URL_PATH=
SERVERHOSTNAME=batdetectai.kitware.com

# Client Environment Variables
NABAT_API_URL=https://api.sciencebase.gov/nabat-graphql/graphql
VITE_APP_API_ROOT=https://batdetectai.kitware.com
VITE_APP_LOGIN_REDIRECT=https://batdetectai.kitware.com
Loading