Compare commits
7 Commits
b9adb6f854
...
37141e87f6
Author | SHA1 | Date |
---|---|---|
Thomas Hobson | 37141e87f6 | |
Thomas Hobson | fb658e1921 | |
Omar Brikaa | 016a8c086f | |
Omar Brikaa | fef00b96f1 | |
Omar Brikaa | 6a47869578 | |
Omar Brikaa | 040e19fdc2 | |
Omar Brikaa | fe2fc374aa |
|
@ -210,6 +210,7 @@ router.ws('/connect', async (ws, req) => {
|
|||
if (job === null) {
|
||||
job = await get_job(msg);
|
||||
|
||||
try {
|
||||
await job.prime();
|
||||
|
||||
ws.send(
|
||||
|
@ -221,9 +222,15 @@ router.ws('/connect', async (ws, req) => {
|
|||
);
|
||||
|
||||
await job.execute(event_bus);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`Error cleaning up job: ${job.uuid}:\n${error}`
|
||||
);
|
||||
throw error;
|
||||
} finally {
|
||||
await job.cleanup();
|
||||
|
||||
ws.close(4999, 'Job Completed');
|
||||
}
|
||||
ws.close(4999, 'Job Completed'); // Will not execute if an error is thrown above
|
||||
} else {
|
||||
ws.close(4000, 'Already Initialized');
|
||||
}
|
||||
|
@ -265,9 +272,13 @@ router.ws('/connect', async (ws, req) => {
|
|||
});
|
||||
|
||||
router.post('/execute', async (req, res) => {
|
||||
let job;
|
||||
try {
|
||||
job = await get_job(req.body);
|
||||
} catch (error) {
|
||||
return res.status(400).json(error);
|
||||
}
|
||||
try {
|
||||
const job = await get_job(req.body);
|
||||
|
||||
await job.prime();
|
||||
|
||||
let result = await job.execute();
|
||||
|
@ -276,11 +287,17 @@ router.post('/execute', async (req, res) => {
|
|||
result.run = result.compile;
|
||||
}
|
||||
|
||||
await job.cleanup();
|
||||
|
||||
return res.status(200).send(result);
|
||||
} catch (error) {
|
||||
return res.status(400).json(error);
|
||||
logger.error(`Error executing job: ${job.uuid}:\n${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
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -35,7 +35,10 @@ expressWs(app);
|
|||
}
|
||||
}
|
||||
});
|
||||
fss.chmodSync(path.join(config.data_directory, globals.data_directories.jobs), 0o711)
|
||||
fss.chmodSync(
|
||||
path.join(config.data_directory, globals.data_directories.jobs),
|
||||
0o711
|
||||
);
|
||||
|
||||
logger.info('Loading packages');
|
||||
const pkgdir = path.join(
|
||||
|
@ -92,7 +95,12 @@ expressWs(app);
|
|||
logger.debug('Calling app.listen');
|
||||
const [address, port] = config.bind_address.split(':');
|
||||
|
||||
app.listen(port, address, () => {
|
||||
const server = app.listen(port, address, () => {
|
||||
logger.info('API server started on', config.bind_address);
|
||||
});
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
server.close();
|
||||
process.exit(0)
|
||||
});
|
||||
})();
|
||||
|
|
|
@ -14,7 +14,7 @@ RUN apt-get update && apt-get install -y unzip autoconf build-essential libssl-d
|
|||
rm -rf /var/lib/apt/lists/* && \
|
||||
update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2
|
||||
|
||||
ADD entrypoint.sh mkindex.sh /
|
||||
ADD entrypoint.sh mkindex.sh serve.py /
|
||||
|
||||
ENTRYPOINT ["bash","/entrypoint.sh"]
|
||||
CMD ["--no-build"]
|
||||
|
|
|
@ -52,7 +52,8 @@ echo "Index created"
|
|||
|
||||
if [[ $SERVER -eq 1 ]]; then
|
||||
echo "Starting index server.."
|
||||
python3 -m http.server
|
||||
# We want the child process to replace the shell to handle signals
|
||||
exec python3 /serve.py
|
||||
else
|
||||
echo "Skipping starting index server"
|
||||
fi
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
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()
|
Loading…
Reference in New Issue