Compare commits

..

No commits in common. "37141e87f66e3ab179018f33a7f02829dbe37d63" and "b9adb6f854d496da12e5591a356455e5b2aed573" have entirely different histories.

6 changed files with 23 additions and 67 deletions

View File

@ -210,27 +210,20 @@ router.ws('/connect', async (ws, req) => {
if (job === null) { if (job === null) {
job = await get_job(msg); job = await get_job(msg);
try { await job.prime();
await job.prime();
ws.send( ws.send(
JSON.stringify({ JSON.stringify({
type: 'runtime', type: 'runtime',
language: job.runtime.language, language: job.runtime.language,
version: job.runtime.version.raw, version: job.runtime.version.raw,
}) })
); );
await job.execute(event_bus); await job.execute(event_bus);
} catch (error) { await job.cleanup();
logger.error(
`Error cleaning up job: ${job.uuid}:\n${error}` ws.close(4999, 'Job Completed');
);
throw error;
} finally {
await job.cleanup();
}
ws.close(4999, 'Job Completed'); // Will not execute if an error is thrown above
} else { } else {
ws.close(4000, 'Already Initialized'); ws.close(4000, 'Already Initialized');
} }
@ -272,13 +265,9 @@ router.ws('/connect', async (ws, req) => {
}); });
router.post('/execute', async (req, res) => { router.post('/execute', async (req, res) => {
let job;
try {
job = await get_job(req.body);
} catch (error) {
return res.status(400).json(error);
}
try { try {
const job = await get_job(req.body);
await job.prime(); await job.prime();
let result = await job.execute(); let result = await job.execute();
@ -287,17 +276,11 @@ router.post('/execute', async (req, res) => {
result.run = result.compile; result.run = result.compile;
} }
await job.cleanup();
return res.status(200).send(result); return res.status(200).send(result);
} catch (error) { } catch (error) {
logger.error(`Error executing job: ${job.uuid}:\n${error}`); return res.status(400).json(error);
return res.status(500).send();
} finally {
try {
await job.cleanup(); // This gets executed before the returns in try/catch
} catch (error) {
logger.error(`Error cleaning up job: ${job.uuid}:\n${error}`);
return res.status(500).send(); // On error, this replaces the return in the outer try-catch
}
} }
}); });

View File

@ -35,10 +35,7 @@ expressWs(app);
} }
} }
}); });
fss.chmodSync( fss.chmodSync(path.join(config.data_directory, globals.data_directories.jobs), 0o711)
path.join(config.data_directory, globals.data_directories.jobs),
0o711
);
logger.info('Loading packages'); logger.info('Loading packages');
const pkgdir = path.join( const pkgdir = path.join(
@ -95,12 +92,7 @@ expressWs(app);
logger.debug('Calling app.listen'); logger.debug('Calling app.listen');
const [address, port] = config.bind_address.split(':'); const [address, port] = config.bind_address.split(':');
const server = app.listen(port, address, () => { app.listen(port, address, () => {
logger.info('API server started on', config.bind_address); logger.info('API server started on', config.bind_address);
}); });
process.on('SIGTERM', () => {
server.close();
process.exit(0)
});
})(); })();

0
packages/bash/5.2.0/build.sh vendored Executable file → Normal file
View File

View File

@ -14,7 +14,7 @@ RUN apt-get update && apt-get install -y unzip autoconf build-essential libssl-d
rm -rf /var/lib/apt/lists/* && \ rm -rf /var/lib/apt/lists/* && \
update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2 update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2
ADD entrypoint.sh mkindex.sh serve.py / ADD entrypoint.sh mkindex.sh /
ENTRYPOINT ["bash","/entrypoint.sh"] ENTRYPOINT ["bash","/entrypoint.sh"]
CMD ["--no-build"] CMD ["--no-build"]

View File

@ -52,8 +52,7 @@ echo "Index created"
if [[ $SERVER -eq 1 ]]; then if [[ $SERVER -eq 1 ]]; then
echo "Starting index server.." echo "Starting index server.."
# We want the child process to replace the shell to handle signals python3 -m http.server
exec python3 /serve.py
else else
echo "Skipping starting index server" echo "Skipping starting index server"
fi fi

View File

@ -1,18 +0,0 @@
import signal
import sys
import http.server
import socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
def signal_handler(sig, frame):
sys.exit(0)
signal.signal(signal.SIGTERM, signal_handler)
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()