Skip to content

Commit

Permalink
Fix access_url and change according to dev vs production mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mkelley committed Aug 21, 2024
1 parent 14c1ef1 commit cb1aaca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
26 changes: 7 additions & 19 deletions sbn_survey_image_service/config/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import inspect
import multiprocessing
from typing import List, Union
from typing import List
from dotenv import load_dotenv, find_dotenv

load_dotenv(find_dotenv(), override=True, verbose=True)
Expand Down Expand Up @@ -40,11 +40,13 @@ class SBNSISEnvironment:
API_HOST: str = "127.0.0.1"
API_PORT: int = 5000
BASE_HREF: str = "/"
PUBLIC_URL: str = "https://sbnsurveys.astro.umd.edu/api"
IS_DAEMON: str = "TRUE"
IS_PRODUCTION: str = "FALSE"

def __init__(self):
key: str
value: Union[str, int, None]
value: str | int | None
for key, value in inspect.getmembers(SBNSISEnvironment):
if key.startswith("_"):
continue
Expand Down Expand Up @@ -101,6 +103,9 @@ def __init__(self):
API_PORT={SBNSISEnvironment.API_PORT}
BASE_HREF={SBNSISEnvironment.BASE_HREF}
# URL used in production
PUBLIC_URL=https://sbnsurveys.astro.umd.edu/api
# QUERY CONFIG
# none
Expand All @@ -119,20 +124,3 @@ def __init__(self):
SBNSIS_LOG_FILE={SBNSISEnvironment.SBNSIS_LOG_FILE}
""".strip()
)


# Debugging block
# print("=========================")
# print(ENV.LIVE_GUNICORN_INSTANCES)
# print(ENV.LIVE_WORKER_INSTANCES)
# print(ENV.DEPLOYMENT_TIER)
# print(ENV.DB_DATABASE)
# print(ENV.DB_PASSWORD)
# print(ENV.DB_USERNAME)
# print()
# print(ENV.CATCH_LOG)
# print(ENV.CATCH_ARCHIVE_PATH)
# print(ENV.CATCH_CUTOUT_PATH)
# print(ENV.CATCH_THUMBNAIL_PATH)
# print(ENV.IS_DAEMON)
# print("=========================")
5 changes: 4 additions & 1 deletion sbn_survey_image_service/scripts/sbnsis.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ def start_dev(self) -> None:
"sbn_survey_image_service.app",
]

env: Dict[str, str] = os.environ.copy()
env["IS_PRODUCTION"] = "FALSE"
try:
subprocess.check_call(cmd)
subprocess.check_call(cmd, env=env)
except KeyboardInterrupt:
pass

Expand All @@ -127,6 +129,7 @@ def start_production(self) -> None:
]

env: Dict[str, str] = os.environ.copy()
env["IS_PRODUCTION"] = "TRUE"
if self.args.daemon:
env["IS_DAEMON"] = "TRUE"
cmd += ["--daemon"]
Expand Down
10 changes: 9 additions & 1 deletion sbn_survey_image_service/services/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

__all__ = ["metadata_query", "metadata_summary"]

from urllib.parse import quote
from typing import Any, List, Tuple
from .database_provider import data_provider_session, Session
from ..models.image import Image
from ..config.env import ENV


def metadata_query(
Expand Down Expand Up @@ -53,6 +55,12 @@ def metadata_query(

images: List[Image] = query.all()

url_base: str = ENV.PUBLIC_URL
if ENV.IS_PRODUCTION.upper() != "TRUE":
url_base = f"http://{ENV.API_HOST}:{ENV.API_PORT}/{ENV.BASE_HREF.lstrip('/')}".rstrip(
"/"
)

for im in images:
matches.append(
{
Expand All @@ -64,7 +72,7 @@ def metadata_query(
"calibration_level": im.calibration_level,
"target": im.target,
"pixel_scale": im.pixel_scale,
"access_url": f"https://sbnsurveys.astro.umd.edu/images/{im.obs_id}?format={format}",
"access_url": f"{url_base}/images/{quote(im.obs_id)}?format={format}",
}
)

Expand Down

0 comments on commit cb1aaca

Please sign in to comment.