Skip to content

Commit

Permalink
Add sozip compression from env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma committed Mar 3, 2024
1 parent b60ea16 commit 3dfe925
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
7 changes: 6 additions & 1 deletion API/api_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import humanize
import requests
import sozipfile.sozipfile as zipfile
from celery import Celery

from src.app import CustomExport, PolygonStats, RawData, S3FileTransfer
Expand All @@ -20,6 +19,7 @@
DEFAULT_HARD_TASK_LIMIT,
DEFAULT_README_TEXT,
DEFAULT_SOFT_TASK_LIMIT,
ENABLE_SOZIP,
ENABLE_TILES,
HDX_HARD_TASK_LIMIT,
HDX_SOFT_TASK_LIMIT,
Expand All @@ -35,6 +35,11 @@
RawDataOutputType,
)

if ENABLE_SOZIP:
import sozipfile.sozipfile as zipfile
else:
from zipfile import zipfile

celery = Celery("Raw Data API")
celery.conf.broker_url = celery_broker_uri
celery.conf.result_backend = celery_backend
Expand Down
2 changes: 2 additions & 0 deletions docs/src/installation/configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The following are the different configuration options that are accepted.
| `ALLOW_BIND_ZIP_FILTER` | `ALLOW_BIND_ZIP_FILTER` | `[API_CONFIG]` | `true` | Enable zip compression for exports | OPTIONAL |
| `EXTRA_README_TXT` | `EXTRA_README_TXT` | `[API_CONFIG]` | `` | Append extra string to export readme.txt | OPTIONAL |
| `ENABLE_TILES` | `ENABLE_TILES` | `[API_CONFIG]` | `false` | Enable Tile Output (Pmtiles and Mbtiles) | OPTIONAL |
| `ENABLE_SOZIP` | `ENABLE_SOZIP` | `[API_CONFIG]` | `false` | Enables sozip compression | OPTIONAL |
| `DEFAULT_QUEUE_NAME` | `DEFAULT_QUEUE_NAME` | `[API_CONFIG]` | `raw_ondemand` | Option to define default queue name| OPTIONAL |
| `DAEMON_QUEUE_NAME` | `DAEMON_QUEUE_NAME` | `[API_CONFIG]` | `raw_daemon` | Option to define daemon queue name for scheduled and long exports | OPTIONAL |
| `ENABLE_POLYGON_STATISTICS_ENDPOINTS` | `ENABLE_POLYGON_STATISTICS_ENDPOINTS` | `[API_CONFIG]` | `False` | Option to enable endpoints related the polygon statistics about the approx buildings,road length in passed polygon| OPTIONAL |
Expand Down Expand Up @@ -117,6 +118,7 @@ API Tokens have expiry date, It is `important to update API Tokens manually each
| `EXPORT_MAX_AREA_SQKM` | `[API_CONFIG]` | Yes | No |
| `USE_CONNECTION_POOLING` | `[API_CONFIG]` | Yes | Yes |
| `ENABLE_TILES` | `[API_CONFIG]` | Yes | Yes |
| `ENABLE_SOZIP` | `[API_CONFIG]` | Yes | Yes |
| `ALLOW_BIND_ZIP_FILTER` | `[API_CONFIG]` | Yes | Yes |
| `EXTRA_README_TXT` | `[API_CONFIG]` | No | Yes |
| `INDEX_THRESHOLD` | `[API_CONFIG]` | No | Yes |
Expand Down
6 changes: 5 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import orjson
import psycopg2.extras
import requests
import sozipfile.sozipfile as zipfile
from area import area
from fastapi import HTTPException
from geojson import FeatureCollection
Expand All @@ -53,6 +52,7 @@
ENABLE_CUSTOM_EXPORTS,
ENABLE_HDX_EXPORTS,
ENABLE_POLYGON_STATISTICS_ENDPOINTS,
ENABLE_SOZIP,
ENABLE_TILES,
EXPORT_MAX_AREA_SQKM,
)
Expand Down Expand Up @@ -88,6 +88,10 @@
)
from src.validation.models import EXPORT_TYPE_MAPPING, RawDataOutputType

if ENABLE_SOZIP:
import sozipfile.sozipfile as zipfile
else:
from zipfile import zipfile
# import instance for pooling
if use_connection_pooling:
from src.db_session import database_instance
Expand Down
6 changes: 6 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ def not_raises(func, *args, **kwargs):
"ALLOW_BIND_ZIP_FILTER",
config.getboolean("API_CONFIG", "ALLOW_BIND_ZIP_FILTER", fallback=False),
)

ENABLE_SOZIP = get_bool_env_var(
"ENABLE_SOZIP",
config.getboolean("API_CONFIG", "ENABLE_SOZIP", fallback=False),
)

ENABLE_TILES = get_bool_env_var(
"ENABLE_TILES", config.getboolean("API_CONFIG", "ENABLE_TILES", fallback=False)
)
Expand Down

0 comments on commit 3dfe925

Please sign in to comment.