Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Code improvements and support for more output formats #340

Open
wants to merge 156 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
9cf5f24
added flower celery and redis
kshitijrajsharma Sep 21, 2022
0a96256
added background task
kshitijrajsharma Sep 21, 2022
1f351ab
added pickle serializer
kshitijrajsharma Sep 21, 2022
2dcc8a4
fixed return error too
kshitijrajsharma Sep 21, 2022
bf62819
added task id to export name itself so that it will be easy to track
kshitijrajsharma Sep 21, 2022
db168d7
updated readme
kshitijrajsharma Sep 22, 2022
8708f29
applied versioning on rawdata snapshot
kshitijrajsharma Sep 22, 2022
8ddfd34
updated version of click
kshitijrajsharma Sep 22, 2022
59ce9bb
enabled fiona
kshitijrajsharma Sep 22, 2022
3959423
added docker workflow
kshitijrajsharma Sep 22, 2022
2f181c0
ignored all .out files
kshitijrajsharma Sep 22, 2022
78b5d7e
remove fiona since its no longer used
kshitijrajsharma Sep 22, 2022
455dda9
Merge branch 'feature/celery' of https://github.com/hotosm/galaxy-api…
kshitijrajsharma Sep 22, 2022
f3041e9
added try except block
kshitijrajsharma Sep 22, 2022
ec6654f
added config file validation and restored previous docker file
kshitijrajsharma Sep 22, 2022
b795f54
removed systemctl part
kshitijrajsharma Sep 22, 2022
fb6ba25
updated docs
kshitijrajsharma Sep 22, 2022
9c25472
Merge branch 'develop' into feature/celery
kshitijrajsharma Sep 22, 2022
3af19ce
updated config doc
kshitijrajsharma Sep 22, 2022
f9dab03
Update GETTING_STARTED_WITH_DOCKER.md
kshitijrajsharma Sep 22, 2022
3d02bb9
Update GETTING_STARTED_WITH_DOCKER.md
kshitijrajsharma Sep 22, 2022
c057081
Update README.md
kshitijrajsharma Sep 22, 2022
5b36c99
Update GETTING_STARTED_WITH_DOCKER.md
kshitijrajsharma Sep 22, 2022
2f161f2
Update README.md
kshitijrajsharma Sep 22, 2022
4354fa0
Update README.md
kshitijrajsharma Sep 22, 2022
7af6549
Update CONFIG_DOC.md
kshitijrajsharma Sep 22, 2022
aad8870
removed config sample unnecessary text and moved instructions to conf…
kshitijrajsharma Sep 22, 2022
b5f99c6
changed workflow for unit test with postgis image
kshitijrajsharma Sep 22, 2022
e2b8a74
fixed yaml indent error
kshitijrajsharma Sep 22, 2022
00dcf8a
indent fix
kshitijrajsharma Sep 22, 2022
7a45838
added postgres
kshitijrajsharma Sep 22, 2022
be3988d
added sudo command
kshitijrajsharma Sep 22, 2022
7c430ac
tet create database option in github action
kshitijrajsharma Sep 22, 2022
9a990d9
check to insert data
kshitijrajsharma Sep 22, 2022
72e6a84
Update CONFIG_DOC.md
kshitijrajsharma Sep 22, 2022
ebf5630
removed auto remove
kshitijrajsharma Sep 22, 2022
3c782a0
removed typo
kshitijrajsharma Sep 22, 2022
c9c5039
check for file path
kshitijrajsharma Sep 22, 2022
31f681b
rerun with filepath
kshitijrajsharma Sep 22, 2022
d173883
added password
kshitijrajsharma Sep 22, 2022
15c6a51
added host information
kshitijrajsharma Sep 22, 2022
eea2106
added -c option
kshitijrajsharma Sep 22, 2022
1d5dd9c
added config section and added insight only
kshitijrajsharma Sep 22, 2022
499bb3f
removed space
kshitijrajsharma Sep 22, 2022
c8e937a
testing workflow
kshitijrajsharma Sep 22, 2022
6a7040a
removed space
kshitijrajsharma Sep 22, 2022
a2ceecd
fixed yml error
kshitijrajsharma Sep 22, 2022
340766a
test
kshitijrajsharma Sep 22, 2022
5b7c96d
added password export option
kshitijrajsharma Sep 22, 2022
4a6a78c
changed password
kshitijrajsharma Sep 22, 2022
ed97604
added db add data
kshitijrajsharma Sep 22, 2022
64c4544
reverted
kshitijrajsharma Sep 22, 2022
93bd453
droped idea of db insert
kshitijrajsharma Sep 22, 2022
4c92ca5
changed to psql 12
kshitijrajsharma Sep 22, 2022
c63e974
added psql 14 postgis
kshitijrajsharma Sep 22, 2022
cd697ce
changed scripts
kshitijrajsharma Sep 22, 2022
f9538a0
final test for psql 14
kshitijrajsharma Sep 22, 2022
97498ff
check psql version
kshitijrajsharma Sep 22, 2022
aae7572
apt install
kshitijrajsharma Sep 22, 2022
a285edf
changed postgis command
kshitijrajsharma Sep 22, 2022
e916c5b
opted old method
kshitijrajsharma Sep 22, 2022
7501bb4
final test
kshitijrajsharma Sep 22, 2022
c882905
setup test with the database
kshitijrajsharma Sep 22, 2022
3a66d87
added port info
kshitijrajsharma Sep 22, 2022
b09f727
exported password
kshitijrajsharma Sep 22, 2022
5e2dd87
binded port of redis
kshitijrajsharma Sep 22, 2022
338f557
updated doc for the docker compose
kshitijrajsharma Sep 22, 2022
5121305
updated sample
kshitijrajsharma Sep 22, 2022
28946dc
Update GETTING_STARTED_WITH_DOCKER.md
kshitijrajsharma Sep 22, 2022
3bf13e8
Update CONFIG_DOC.md
kshitijrajsharma Sep 22, 2022
0b63d6a
Update CONFIG_DOC.md
kshitijrajsharma Sep 22, 2022
194628e
Update README.md
kshitijrajsharma Sep 22, 2022
4f1037a
Check if fails or not for worker
kshitijrajsharma Sep 22, 2022
88f857a
handled error
kshitijrajsharma Sep 22, 2022
394c34c
formatted worker
kshitijrajsharma Sep 22, 2022
59bda45
added build and separated from unit test
kshitijrajsharma Sep 23, 2022
bc01ff9
redis minimal installation added
kshitijrajsharma Sep 23, 2022
c952c75
removed double installation of redis
kshitijrajsharma Sep 23, 2022
ee806aa
moved db section to top
kshitijrajsharma Sep 23, 2022
27b46d8
check for server error
kshitijrajsharma Sep 23, 2022
f18c91a
added timeout
kshitijrajsharma Sep 23, 2022
e07ef58
changed redis url and get api
kshitijrajsharma Sep 23, 2022
a74df8d
added flower and mapathon endpoint test
kshitijrajsharma Sep 23, 2022
1e1291a
fixed typo
kshitijrajsharma Sep 23, 2022
e01775f
updated documentation along with curl command
kshitijrajsharma Sep 23, 2022
7096b7f
curl command setup
kshitijrajsharma Sep 23, 2022
ad9ead2
updated readme
kshitijrajsharma Sep 23, 2022
325e38f
updated doc
kshitijrajsharma Sep 23, 2022
a77f4ae
check db connection
kshitijrajsharma Sep 23, 2022
1a50d45
check if we can install gdal without update
kshitijrajsharma Sep 23, 2022
5b1ffba
check with env
kshitijrajsharma Sep 23, 2022
825b240
check with disabled upgrade command
kshitijrajsharma Sep 23, 2022
5f49c51
added rawdata snapshot
kshitijrajsharma Sep 23, 2022
82e14cd
Update README.md
kshitijrajsharma Sep 23, 2022
a18b781
Update README.md
kshitijrajsharma Sep 23, 2022
e6cba6b
Update README.md
kshitijrajsharma Sep 23, 2022
b058ee5
Update README.md
kshitijrajsharma Sep 23, 2022
12b2f90
Update README.md
kshitijrajsharma Sep 23, 2022
79f9482
Changed URL with relative and fixed typo
kshitijrajsharma Sep 23, 2022
7141f6c
changed url to relative url
kshitijrajsharma Sep 23, 2022
ab0c94a
resolved healthcheck url
kshitijrajsharma Sep 23, 2022
8ccf55d
added note for docker users to use local postgres from container
kshitijrajsharma Sep 23, 2022
13b8a25
added supporting doc if connection fails from container to psql
kshitijrajsharma Sep 23, 2022
2d7ce77
formatted md file
kshitijrajsharma Sep 23, 2022
2b1c0b1
resolved docker cache on dependencies and updated options to connect …
kshitijrajsharma Sep 24, 2022
b44e4ab
added pickle and status
kshitijrajsharma Sep 24, 2022
8bcbd72
round digit to 2 decimal for binded file size
kshitijrajsharma Sep 24, 2022
f349755
Introduces rate limit
kshitijrajsharma Sep 24, 2022
c9b9b7b
resolved mapathon detail docs
kshitijrajsharma Sep 24, 2022
fd28684
resolved raise exception if config file not found
kshitijrajsharma Sep 24, 2022
0116b0c
removed string in error file
kshitijrajsharma Sep 24, 2022
b55ff6b
reverted lgic with previous
kshitijrajsharma Sep 25, 2022
a9a0c98
Reformatted boto exceptions
kshitijrajsharma Sep 26, 2022
b3ba9e4
ignore all log files
kshitijrajsharma Sep 26, 2022
e1ab356
disabled logs
kshitijrajsharma Sep 26, 2022
f2db19f
reformatted
kshitijrajsharma Sep 27, 2022
40e9394
changed worker to dev debug setup and added fix for ogr2ogr devsetup
kshitijrajsharma Sep 27, 2022
276b527
removed test sql
kshitijrajsharma Sep 27, 2022
8f12d73
added geoflatbuff file system
kshitijrajsharma Sep 28, 2022
80deb65
added . output type in file name
kshitijrajsharma Sep 28, 2022
eddbbe4
formatted code , used path option for paths improved workflow for raw…
kshitijrajsharma Sep 29, 2022
bbd3013
removed shp limit since we don't need it we have queue in place , mov…
kshitijrajsharma Sep 29, 2022
1a3a6f4
fixed bug on filename
kshitijrajsharma Sep 29, 2022
12a198e
added kml and flatgeobuff file format
kshitijrajsharma Sep 29, 2022
87cab1a
updated doc !
kshitijrajsharma Sep 29, 2022
da59948
Updated the feature !
kshitijrajsharma Sep 29, 2022
614d2d3
removed unnecessary library
kshitijrajsharma Sep 29, 2022
3f6b2b5
added docstring for bind option
kshitijrajsharma Sep 29, 2022
17a38d6
changed limiter backend to redis #346
kshitijrajsharma Sep 30, 2022
ff52611
Changed port for flower
kshitijrajsharma Sep 30, 2022
e0a2b85
added geopackage file format
kshitijrajsharma Sep 30, 2022
1451d0e
read grid index threshold from config
kshitijrajsharma Sep 30, 2022
fd5d5d0
added sample data to docker postgres
kshitijrajsharma Sep 30, 2022
a5c13ce
added docker config
kshitijrajsharma Sep 30, 2022
f2bab05
update port info
kshitijrajsharma Sep 30, 2022
2254bae
changed port for flower
kshitijrajsharma Sep 30, 2022
8d50ded
Update CONFIG_DOC.md
kshitijrajsharma Sep 30, 2022
15913fc
Merge branch 'feature/geoflatbuf' of https://github.com/hotosm/galaxy…
kshitijrajsharma Sep 30, 2022
a024dad
Added config for docker setup
kshitijrajsharma Sep 30, 2022
f504b65
changed port to 4000
kshitijrajsharma Sep 30, 2022
0fbffee
fixed chmod command
kshitijrajsharma Sep 30, 2022
3671987
added ref sh
kshitijrajsharma Sep 30, 2022
8f5190d
added link to readme
kshitijrajsharma Sep 30, 2022
71b339b
added troubleshoot for executable .sh
kshitijrajsharma Sep 30, 2022
f94d5a6
Update GETTING_STARTED_WITH_DOCKER.md
kshitijrajsharma Sep 30, 2022
23d9982
formatted readme
kshitijrajsharma Sep 30, 2022
722dc69
added default output type as geojson from worker
kshitijrajsharma Oct 3, 2022
411291d
reformatted response
kshitijrajsharma Oct 3, 2022
b954133
reformatted response to galaxy_export
kshitijrajsharma Oct 3, 2022
26125ec
typo
kshitijrajsharma Oct 3, 2022
471894d
Update GETTING_STARTED_WITH_DOCKER.md
kshitijrajsharma Oct 4, 2022
8bad591
Update README.md
kshitijrajsharma Oct 4, 2022
6597706
fixed bug on select condition
kshitijrajsharma Oct 4, 2022
d2527a2
fixed select query for relation
kshitijrajsharma Oct 4, 2022
1624014
changed rawdata response type
kshitijrajsharma Oct 5, 2022
f3a4d86
changed to timestamp rather than difference
kshitijrajsharma Oct 10, 2022
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
43 changes: 31 additions & 12 deletions .github/workflows/Unit-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@ jobs:
deploy:
runs-on:
ubuntu-latest

services:
postgres:
image: postgis/postgis:14-3.3
env:
POSTGRES_PASSWORD: admin
POSTGRES_DB: insights
ports:
- 5434:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 2
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Check postgresql version
run: |
psql -V
- name: Remove postgresql version 14
- name: Clean up PSQL
run: |
sudo apt-get --purge remove postgresql
sudo apt-get purge postgresql*
Expand All @@ -36,17 +41,31 @@ jobs:
run: |
sudo apt-get update
sudo apt install postgis postgresql-12-postgis-3
- name: Install gdal
run: |
sudo apt-add-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install gdal-bin libgdal-dev


- name: Create Databases
run : |
export PGPASSWORD='admin';
psql -U postgres -h localhost -p 5434 -c "CREATE DATABASE underpass;"
psql -U postgres -h localhost -p 5434 -c "CREATE DATABASE tm;"
psql -U postgres -h localhost -p 5434 -c "CREATE DATABASE raw;"

- name: Insert sample db data
run : |
export PGPASSWORD='admin';
psql -U postgres -h localhost -p 5434 insights < tests/src/fixtures/insights.sql
psql -U postgres -h localhost -p 5434 raw < tests/src/fixtures/raw_data.sql
psql -U postgres -h localhost -p 5434 underpass < tests/src/fixtures/underpass.sql
wget https://raw.githubusercontent.com/hotosm/tasking-manager/develop/tests/database/tasking-manager.sql
psql -U postgres -h localhost -p 5434 tm < tasking-manager.sql

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -e .
- name: Creating config.txt
run: |
mv src/config.txt.sample src/config.txt
- name: Run Tests
run: |
py.test -v -s
py.test -v -s
86 changes: 86 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Check Build
on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop

jobs:
build:
timeout-minutes: 4
runs-on: ubuntu-latest
services:
postgres:
image: postgis/postgis:14-3.3
env:
POSTGRES_PASSWORD: admin
POSTGRES_DB: insights
ports:
- 5434:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 2
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8

- name: Create Databases
run: |
export PGPASSWORD='admin';
psql -U postgres -h localhost -p 5434 -c "CREATE DATABASE underpass;"
psql -U postgres -h localhost -p 5434 -c "CREATE DATABASE tm;"
psql -U postgres -h localhost -p 5434 -c "CREATE DATABASE raw;"

- name: Insert sample db data
run: |
export PGPASSWORD='admin';
psql -U postgres -h localhost -p 5434 insights < tests/src/fixtures/insights.sql
psql -U postgres -h localhost -p 5434 insights < tests/src/fixtures/mapathon_summary.sql
psql -U postgres -h localhost -p 5434 raw < tests/src/fixtures/raw_data.sql
psql -U postgres -h localhost -p 5434 underpass < tests/src/fixtures/underpass.sql
wget https://raw.githubusercontent.com/hotosm/tasking-manager/develop/tests/database/tasking-manager.sql
psql -U postgres -h localhost -p 5434 tm < tasking-manager.sql

- name: Install gdal
run: |
sudo apt-get -y install gdal-bin python3-gdal && sudo apt-get -y autoremove && sudo apt-get clean

- name: Install redis
run: |
sudo apt install lsb-release
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis
redis-cli ping

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -e .
- name: Creating config.txt
run: |
mv src/config.txt.sample src/config.txt
- name: Run uvicorn server
run: |
uvicorn API.main:app &
env:
PORT: 8000
- name: Run celery server
run: |
celery --app API.api_worker worker --loglevel=INFO &
- name: Run flower dashboard
run: |
celery --app API.api_worker flower --port=5555 --broker=redis://localhost:6379/ &
- name: Run mapathon summary endpoint
run: |
curl -d '{"project_ids": [11224, 10042, 9906, 1381, 11203, 10681, 8055, 8732, 11193, 7305,11210, 10985, 10988, 11190, 6658, 5644, 10913, 6495, 4229],"fromTimestamp":"2021-08-27T9:00:00","toTimestamp":"2021-08-27T11:00:00","hashtags": ["mapandchathour2021"]}' -H 'Content-Type: application/json' http://127.0.0.1:8000/v1/mapathon/summary/
- name: Run rawdata current snapshot
run: |
curl -d '{"geometry":{"type":"Polygon","coordinates":[[[83.96919250488281,28.194446860487773],[83.99751663208006,28.194446860487773],[83.99751663208006,28.214869548073377],[83.96919250488281,28.214869548073377],[83.96919250488281,28.194446860487773]]]}}' -H 'Content-Type: application/json' http://127.0.0.1:8000/v2/raw-data/current-snapshot/
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ build
newrelic.ini
newrelic.ini_backup
exports
nohup.out
postgres-data
*.out
*.log
121 changes: 121 additions & 0 deletions API/api_worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import os
import pathlib
import orjson
import shutil
import time
import requests
from datetime import datetime as dt
import zipfile
from celery import Celery
from src.galaxy.config import config
from fastapi.responses import JSONResponse
from src.galaxy.query_builder.builder import format_file_name_str
from src.galaxy.validation.models import RawDataOutputType
from src.galaxy.app import RawData, S3FileTransfer
from src.galaxy.config import use_s3_to_upload, logger as logging, config, allow_bind_zip_filter

celery = Celery(__name__)
celery.conf.broker_url = config.get(
"CELERY", "CELERY_BROKER_URL", fallback="redis://localhost:6379"
)
celery.conf.result_backend = config.get(
"CELERY", "CELERY_RESULT_BACKEND", fallback="redis://localhost:6379"
) # using redis as backend , make sure you have redis server started on your system on port 6379

celery.conf.task_serializer = 'pickle'
celery.conf.result_serializer = 'pickle'
celery.conf.accept_content = ['application/json', 'application/x-python-serialize']


@celery.task(bind=True, name="process_raw_data")
def process_raw_data(self, params):
try:
start_time = dt.now()
bind_zip=params.bind_zip if allow_bind_zip_filter else True
# unique id for zip file and geojson for each export
params.output_type = params.output_type if params.output_type else RawDataOutputType.GEOJSON.value
params.file_name=format_file_name_str(params.file_name) if params.file_name else 'Galaxy_export'
exportname = f"{params.file_name}_{str(self.request.id)}_{params.output_type}"

logging.info("Request %s received", exportname)

geom_area, working_dir = RawData(params).extract_current_data(exportname)
inside_file_size = 0
if bind_zip:
logging.debug('Zip Binding Started !')
# saving file in temp directory instead of memory so that zipping file will not eat memory
upload_file_path = os.path.join(working_dir,os.pardir,f"{exportname}.zip")

zf = zipfile.ZipFile(upload_file_path, "w", zipfile.ZIP_DEFLATED)
for file_path in pathlib.Path(working_dir).iterdir():
zf.write(file_path, arcname=file_path.name)
inside_file_size += os.path.getsize(file_path)

# Compressing geojson file
zf.writestr("clipping_boundary.geojson",
orjson.dumps(dict(params.geometry)))

zf.close()
logging.debug('Zip Binding Done !')
else:
for file_path in pathlib.Path(working_dir).iterdir():
upload_file_path=file_path
inside_file_size += os.path.getsize(file_path)
break # only take one file inside dir , if contains many it should be inside zip
# check if download url will be generated from s3 or not from config
if use_s3_to_upload:
file_transfer_obj = S3FileTransfer()
download_url = file_transfer_obj.upload(upload_file_path, exportname, file_suffix='zip' if bind_zip else params.output_type.lower())
else:
download_url = str(upload_file_path) # give the static file download url back to user served from fastapi static export path

# getting file size of zip , units are in bytes converted to mb in response
zip_file_size = os.path.getsize(upload_file_path)
# watches the status code of the link provided and deletes the file if it is 200
if use_s3_to_upload:
watch_s3_upload(download_url, upload_file_path)
if use_s3_to_upload or bind_zip:
#remove working dir from the machine , if its inside zip / uploaded we no longer need it
remove_file(working_dir)
response_time = dt.now() - start_time
response_time_str = str(response_time)
logging.info(f"Done Export : {exportname} of {round(inside_file_size/1000000)} MB / {geom_area} sqkm in {response_time_str}")
return {"download_url": download_url, "file_name": params.file_name, "process_time": response_time_str, "query_area": f"{round(geom_area,2)} Sq Km", "binded_file_size": f"{round(inside_file_size/1000000,2)} MB", "zip_file_size_bytes": zip_file_size}

except Exception as ex:
raise ex


def remove_file(path: str) -> None:
"""Used for removing temp file dir and its all content after zip file is delivered to user"""
try:
shutil.rmtree(path)
except OSError as ex:
logging.error("Error: %s - %s.", ex.filename, ex.strerror)


def watch_s3_upload(url: str, path: str) -> None:
"""Watches upload of s3 either it is completed or not and removes the temp file after completion

Args:
url (_type_): url generated by the script where data will be available
path (_type_): path where temp file is located at
"""
start_time = time.time()
remove_temp_file = True
check_call = requests.head(url).status_code
if check_call != 200:
logging.debug("Upload is not done yet waiting ...")
while check_call != 200: # check until status is not green
check_call = requests.head(url).status_code
if time.time() - start_time > 300:
logging.error(
"Upload time took more than 5 min , Killing watch : %s , URL : %s", path, url)
remove_temp_file = False # don't remove the file if upload fails
break
time.sleep(3) # check each 3 second
# once it is verfied file is uploaded finally remove the file
if remove_temp_file:
logging.debug(
"File is uploaded at %s , flushing out from %s", url, path)
os.unlink(path)
45 changes: 0 additions & 45 deletions API/download_export.py

This file was deleted.

22 changes: 16 additions & 6 deletions API/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@
from .hashtag_stats import router as hashtag_router
from .tasking_manager import router as tm_router
from .raw_data import router as raw_data_router
from .download_export import router as download_router
# from .test_router import router as test_router
from .tasks import router as tasks_router
from .status import router as status_router
from src.galaxy.db_session import database_instance
from src.galaxy.config import use_connection_pooling, use_s3_to_upload, logger as logging, config
from src.galaxy.config import limiter, export_path, use_connection_pooling, use_s3_to_upload, logger as logging, config
from fastapi_versioning import VersionedFastAPI
from slowapi import _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
from fastapi.staticfiles import StaticFiles

# only use sentry if it is specified in config blocks
if config.get("SENTRY", "dsn", fallback=None):
Expand All @@ -50,12 +52,15 @@
traces_sample_rate=config.get("SENTRY", "rate")
)


run_env = config.get("API_CONFIG", "env", fallback='prod')
if run_env.lower() == 'dev':
# This is used for local setup for auth login
import os
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'



app = FastAPI(title="Galaxy API")

# app.include_router(test_router)
Expand All @@ -71,15 +76,20 @@
app.include_router(tm_router)
app.include_router(status_router)
app.include_router(raw_data_router)
app.include_router(tasks_router)


if use_s3_to_upload is False:
# only mount the disk if config is set to disk
app.include_router(download_router)


app = VersionedFastAPI(app, enable_latest=True,
version_format='{major}', prefix_format='/v{major}')

if use_s3_to_upload is False:
# only mount the disk if config is set to disk
app.mount("/exports", StaticFiles(directory=export_path), name="exports")

app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)

origins = ["*"]

Expand Down
Loading