Skip to content

Commit

Permalink
Add helper scripts and SINGLE_RUN params for those scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
ttmx committed Jul 17, 2024
1 parent 4c73a07 commit 3c58102
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
},
"[jsonc]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
},
"eslint.useFlatConfig": false
}
75 changes: 75 additions & 0 deletions gen-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash


cleanup() {
echo "Cleaning up..."
kill $API_PID
kill $STANDALONE_PID
kill -9 $MAIN_API_PID
kill $QUEUE_MANAGER_PID
kill $PRINTER_PID1
kill $PRINTER_PID2
exit 1
}

# Trap SIGINT signal (Ctrl+C)
trap cleanup SIGINT

# Start the API server and save its PID
(
cd ../api/parse-network/ &&
set -a &&
source .env &&
set +a &&
SINGLE_RUN=true GTFS_URL=$1 npm run start
) &&
API_PID=$!

# Build the renderer
(
cd ./renderer/ && npm run build && cp .next/static .next/standalone/.next/static -r
) &&
wait

# Start the standalone server and save its PID
(
cd ./renderer/ && API_URL=http://localhost:5050 node .next/standalone/server.js
) &
STANDALONE_PID=$!

# Start the main API server and save its PID
(
cd ../api/server/ && npm run start > /dev/null
) &
MAIN_API_PID=$!

# Start the queue manager and save its PID
(
cd ./queue-manager/ && sleep 5 && SINGLE_RUN=true npm run start
) &
QUEUE_MANAGER_PID=$!

rm -rf ./printer/pdfs/*
# Start the printer and save its PID
(
cd ./printer/ && sleep 10 && SINGLE_RUN=true npm run start
) &
PRINTER_PID1=$!
(
cd ./printer/ && sleep 10 && SINGLE_RUN=true npm run start
) &
PRINTER_PID2=$!

# Wait for the queue manager and both printer processes to finish
wait $QUEUE_MANAGER_PID
wait $PRINTER_PID1
wait $PRINTER_PID2

# Kill the API server, standalone server, and main API server
kill $API_PID
kill $STANDALONE_PID
kill $MAIN_API_PID

(cd ./printer/pdfs && zip ../../$(date +"%Y-%m-%d")$(basename $1) *.pdf)


2 changes: 2 additions & 0 deletions printer/checkdoublepage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
grep -c "<</Type /Page$" -R $1|awk -F':' '$2 >= 2 { print $1 }' |xargs -n1 basename|tee ./twopages.txt
7 changes: 7 additions & 0 deletions printer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const RENDER_URL = process.env.RENDER_URL || 'http://localhost:3000/schedule';
const PARALLEL = parseInt(process.env.TABS) || 12;
const CACHE_SIZE = PARALLEL * 2;
const REFRESH_AFTER = parseInt(process.env.REFRESH_AFTER) || 100;

const SINGLE_RUN = process.env.SINGLE_RUN == 'true' || false;

console.log(`QUEUE_URL: ${QUEUE_URL}`);
console.log(`RENDER_URL: ${RENDER_URL}`);
console.log(`PARALLEL: ${PARALLEL}`);
Expand Down Expand Up @@ -103,6 +106,10 @@ async function replenishQueue() {
let maybeItem: { finished: boolean, item: string | null } = await response.json();

if (maybeItem.finished) {
if (SINGLE_RUN) {
console.log('Finished processing all items');
process.exit(0);
}
await new Promise(resolve => setTimeout(resolve, 5000));
} else if (maybeItem.item) {
queue.push(maybeItem.item);
Expand Down
3 changes: 2 additions & 1 deletion queue-manager/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dotenv/config';
import process from 'process';
import Fastify from 'fastify';
import { start } from 'repl';
const fastify = Fastify({ logger: false });

const API_URL = process.env.API_URL || 'http://localhost:5050';
const LOG_EVERY = parseInt(process.env.LOG_EVERY) || 100;
const SINGLE_RUN = process.env.SINGLE_RUN == 'true' || false;

let updatedAt:string|null = null;
let queue = [];
Expand All @@ -31,6 +31,7 @@ async function main() {
startTime = currentTime;
}
if (queue.length === 0) {
if (SINGLE_RUN && updatedAt != null) setTimeout(() => { process.exit(0); }, 1000);
return { finished: true, item: null };
}
i++;
Expand Down

0 comments on commit 3c58102

Please sign in to comment.