Skip to content

Commit

Permalink
Describe environment variables for PostgreSQL configuration in readme…
Browse files Browse the repository at this point in the history
… and tile fetch timeout
  • Loading branch information
dqunbp committed Nov 12, 2024
1 parent 54cfacb commit a6a741f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,22 @@ const levels = {
- Click on the Import button.
9. Open the browser and navigate to http://localhost:8001/mosaic-viewer to view the mosaic map.
## Environment variables
| Name | Description | Default Value |
| ----------------------- | --------------------------------------- | --------------- |
| `PGHOST` | PostgreSQL host | |
| `PGUSER` | PostgreSQL user | |
| `PGPASSWORD` | PostgreSQL password | |
| `PGDATABASE` | PostgreSQL database name | `postgres` |
| `OAM_LAYER_ID` | OpenAerialMap layer ID | `openaerialmap` |
| `PORT` | Server port | |
| `BASE_URL` | Root URL of the server | |
| `TITILER_BASE_URL` | URL of your Titiler installation | |
| `TILES_CACHE_DIR_PATH` | Path for the tiles cache | `/tiles` |
| `LOG_LEVEL` | Logging level | |
| `DB_POOL_SIZE` | Size of the PostgreSQL connection pool | `16` |
| `DB_DISABLE_SSL` | Disable SSL for PostgreSQL connection | `false` |
| `TILE_FETCH_TIMEOUT_MS` | Tile fetch timeout in milliseconds | `60000` |
| `FETCH_QUEUE_TTL_MS` | Fetch promise queue TTL in milliseconds | `600000` |
10 changes: 7 additions & 3 deletions src/titiler_fetcher.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ const TITILER_BASE_URL = process.env.TITILER_BASE_URL;
const tileRequestQueue = new PQueue({ concurrency: numCPUs });
const activeTileRequests = new Map();

const TILE_FETCH_TIMEOUT_MS =
Number.parseInt(process.env.TILE_FETCH_TIMEOUT_MS, 10) || 1000 * 60 * 1; // 1 minute default

async function fetchTile(url) {
try {
const responsePromise = got(url, {
timeout: { request: TILE_FETCH_TIMEOUT_MS },
throwHttpErrors: true,
});

Expand All @@ -34,7 +38,7 @@ async function fetchTile(url) {
}
}

const FETCH_QUEUE_TTL = Number.parseInt(process.env.TILE_FETCH_TTL_MS, 10) || 1000 * 60 * 10; // 10 minutes default
const FETCH_QUEUE_TTL_MS = Number.parseInt(process.env.FETCH_QUEUE_TTL_MS, 10) || 1000 * 60 * 10; // 10 minutes default

async function enqueueTileFetching(tileUrl, z, x, y) {
const url = tileUrl.replace("{z}", z).replace("{x}", x).replace("{y}", y);
Expand All @@ -43,10 +47,10 @@ async function enqueueTileFetching(tileUrl, z, x, y) {
}

const request = tileRequestQueue
.add(() => fetchTile(url), { priority: Math.pow(2, z), timeout: FETCH_QUEUE_TTL })
.add(() => fetchTile(url), { priority: Math.pow(2, z), timeout: FETCH_QUEUE_TTL_MS })
.catch((error) => {
if (error.name === "TimeoutError") {
console.error(`Tile request timed out after ${FETCH_QUEUE_TTL}ms for URL: ${url}`);
console.error(`Tile request timed out after ${FETCH_QUEUE_TTL_MS}ms for URL: ${url}`);
} else {
console.error(`Error fetching tile: ${url}`, error);
}
Expand Down

0 comments on commit a6a741f

Please sign in to comment.