From da0e4ed74d75422c99f39238b60b0e5aeaf9d9c2 Mon Sep 17 00:00:00 2001 From: ttmx Date: Mon, 13 May 2024 13:29:37 +0000 Subject: [PATCH] Change running methodology for single docker compose --- docker-compose.local.yml | 17 +++++------------ docker-compose.yml | 25 +++++-------------------- printer/src/index.ts | 15 +++++---------- 3 files changed, 15 insertions(+), 42 deletions(-) diff --git a/docker-compose.local.yml b/docker-compose.local.yml index f5185f6..38f5d4d 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -1,5 +1,3 @@ -version: '3.9' - volumes: certbotdata: serverdb: @@ -91,7 +89,7 @@ services: parse-network: image: ghcr.io/carrismetropolitana/api-parse-network:beta - restart: "no" + restart: unless-stopped logging: options: max-size: '1m' @@ -101,9 +99,9 @@ services: - NETWORKDB_HOST=networkdb - NETWORKDB_USER=networkdbuser - NETWORKDB_PASSWORD=networkdbpassword - - SINGLE_RUN=true - - GTFS_URL=https://github.com/carrismetropolitana/gtfs/raw/live/CarrisMetropolitana.zip - # - GTFS_URL=https://storage.carrismetropolitana.pt/static/gtfs/GTFS_a4_ref_20240502.zip + # - SINGLE_RUN=true + # - GTFS_URL=https://github.com/carrismetropolitana/gtfs/raw/live/CarrisMetropolitana.zip + - GTFS_URL=https://storage.carrismetropolitana.pt/static/gtfs/GTFS_a4_ref_20240502.zip depends_on: - serverdb - networkdb @@ -147,15 +145,12 @@ services: - API_URL=http://api:5050 # ports: # - "5052:5052" - depends_on: - parse-network: - condition: service_completed_successfully pdf-printer: build: context: ./printer dockerfile: Dockerfile - restart: "no" + restart: unless-stopped logging: options: max-size: '1m' @@ -166,7 +161,5 @@ services: - RENDER_URL=http://pdf-renderer:3000/schedule - QUEUE_URL=http://queue:5052 depends_on: - parse-network: - condition: service_completed_successfully queue: condition: service_started \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 4406c40..8dbf528 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,3 @@ -version: '3.9' - -volumes: - certbotdata: - serverdb: - -services: - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # @@ -72,7 +64,7 @@ services: parse-network: image: ghcr.io/carrismetropolitana/api-parse-network:beta - restart: "no" + restart: unless-stopped logging: options: max-size: '1m' @@ -82,9 +74,9 @@ services: - NETWORKDB_HOST=networkdb - NETWORKDB_USER=networkdbuser - NETWORKDB_PASSWORD=networkdbpassword - - SINGLE_RUN=true - - GTFS_URL=https://github.com/carrismetropolitana/gtfs/raw/live/CarrisMetropolitana.zip - # - GTFS_URL=https://storage.carrismetropolitana.pt/static/gtfs/GTFS_a4_ref_20240502.zip + # - SINGLE_RUN=true + # - GTFS_URL=https://github.com/carrismetropolitana/gtfs/raw/live/CarrisMetropolitana.zip + - GTFS_URL=https://storage.carrismetropolitana.pt/static/gtfs/GTFS_a4_ref_20240502.zip depends_on: - serverdb - networkdb @@ -104,8 +96,6 @@ services: - API_URL=http://api:5050 depends_on: - api - ports: - - "3005:3000" healthcheck: test: curl -f http://localhost:3000 || exit 1 interval: 5s @@ -124,13 +114,10 @@ services: - API_URL=http://api:5050 # ports: # - "5052:5052" - depends_on: - parse-network: - condition: service_completed_successfully pdf-printer: image: ghcr.io/carrismetropolitana/pdf-maker-printer:production - restart: "no" + restart: unless-stopped logging: options: max-size: '1m' @@ -141,7 +128,5 @@ services: - RENDER_URL=http://pdf-renderer:3000/schedule - QUEUE_URL=http://queue:5052 depends_on: - parse-network: - condition: service_completed_successfully queue: condition: service_started \ No newline at end of file diff --git a/printer/src/index.ts b/printer/src/index.ts index 0e6b19b..10249a3 100644 --- a/printer/src/index.ts +++ b/printer/src/index.ts @@ -93,21 +93,16 @@ async function parallelGen(PARALLEL: number, timetablePaths: AsyncGenerator= CACHE_SIZE) { - break; - } - + while (queue.length < CACHE_SIZE) { try { let response = await fetch(`${QUEUE_URL}/nextitem`); let maybeItem: { finished: boolean, item: string | null } = await response.json(); if (maybeItem.finished) { - finished = true; + await new Promise(resolve => setTimeout(resolve, 5000)); } else if (maybeItem.item) { queue.push(maybeItem.item); // console.log(`Item added: ${maybeItem.item}`); @@ -121,12 +116,12 @@ async function replenishQueue() { // Asynchronous generator function to manage the queue and yield items async function* itemGenerator() { - while (!finished || queue.length > 0) { + while (true) { // console.log(`Queue length: ${queue.length}, finished: ${finished}`); - if (!finished && queue.length === 0) { + if (queue.length === 0) { await replenishQueue(); // Call replenishQueue without awaiting it console.log('Had to wait for replenishQueue'); - } else if (queue.length < CACHE_SIZE && !finished) { + } else if (queue.length < CACHE_SIZE) { replenishQueue(); // Call replenishQueue without awaiting it }