Skip to content

Commit

Permalink
Hook up the background transpiler.
Browse files Browse the repository at this point in the history
*Triggers the transpilation process upon server startup and at regular intervals (every 5 minutes).
  • Loading branch information
goetzrrGit committed Feb 23, 2024
1 parent bf869ec commit 35ed269
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions sequencing-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { getHasuraSession, canUserPerformAction, ENDPOINTS_WHITELIST } from './u
import type { Result } from '@nasa-jpl/aerie-ts-user-code-runner/build/utils/monads';
import type { CacheItem, UserCodeError } from '@nasa-jpl/aerie-ts-user-code-runner';
import { PromiseThrottler } from './utils/PromiseThrottler.js';
import { backgroundTranspiler } from './backgroundTranspiler.js';

const logger = getLogger('app');

Expand All @@ -39,7 +40,9 @@ app.use(bodyParser.json({ limit: '100mb' }));

DbExpansion.init();
export const db = DbExpansion.getDb();

export let graphqlClient = new GraphQLClient(getEnv().MERLIN_GRAPHQL_URL, {
headers: { 'x-hasura-admin-secret': getEnv().HASURA_GRAPHQL_ADMIN_SECRET },
});
export const piscina = new Piscina({
filename: new URL('worker.js', import.meta.url).pathname,
minThreads: parseInt(getEnv().SEQUENCING_WORKER_NUM),
Expand All @@ -62,10 +65,6 @@ export type Context = {
};

app.use(async (req: Request, res: Response, next: NextFunction) => {
const graphqlClient = new GraphQLClient(getEnv().MERLIN_GRAPHQL_URL, {
headers: { 'x-hasura-admin-secret': getEnv().HASURA_GRAPHQL_ADMIN_SECRET },
});

// Check and make sure the user making the request has the required permissions.
if (
!ENDPOINTS_WHITELIST.has(req.url) &&
Expand Down Expand Up @@ -248,3 +247,19 @@ app.listen(PORT, () => {
Total workers started: ${piscina.threads.length},
Heap Size per Worker: ${getEnv().SEQUENCING_MAX_WORKER_HEAP_MB} MB`);
});

if (getEnv().TRANSPILER_ENABLED === 'true') {
//log that the tranpiler is on
logger.info(`Background Transpiler is 'on'`);
// Immediately call the background transpiler
await backgroundTranspiler();
// Then continue calling it every 5 minutes
let transpilerInProgress: boolean = false;
setInterval(async () => {
if (!transpilerInProgress) {
transpilerInProgress = true;
await backgroundTranspiler();
transpilerInProgress = false;
}
}, 60 * 5 * 1000);
}

0 comments on commit 35ed269

Please sign in to comment.