Skip to content

Commit

Permalink
Change running methodology for single docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
ttmx committed May 13, 2024
1 parent 8efbae1 commit da0e4ed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 42 deletions.
17 changes: 5 additions & 12 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.9'

volumes:
certbotdata:
serverdb:
Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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
25 changes: 5 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
version: '3.9'

volumes:
certbotdata:
serverdb:

services:

# # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # #

Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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
15 changes: 5 additions & 10 deletions printer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,16 @@ async function parallelGen(PARALLEL: number, timetablePaths: AsyncGenerator<stri
}

let queue: string[] = [];
let finished = false;

// Helper function to fetch items and replenish the queue
async function replenishQueue() {
while (!finished && queue.length < CACHE_SIZE) {
if (finished || queue.length >= 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}`);
Expand All @@ -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
}

Expand Down

0 comments on commit da0e4ed

Please sign in to comment.