Skip to content

Commit

Permalink
fix: add delay to start and add env to ecosystem.config.cjs
Browse files Browse the repository at this point in the history
Signed-off-by: Raphael Arce <[email protected]>
  • Loading branch information
raphael-arce committed Oct 2, 2024
1 parent 79c5777 commit 717399d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
6 changes: 4 additions & 2 deletions ecosystem.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ module.exports = {
apps: [
{
name: "idea-machine-backend",
script: "index.js",
args: "--env-file=.env",
script: "./index.js",
env: {
// ADD YOUR ENVIRONMENT VARIABLES HERE
}
},
],
};
34 changes: 18 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import bluetoothSerialMonitors from "./services/bluetooth/bluetooth.js";
import server from "./services/rest/rest.js";
import { webSocketServer } from "./services/socket/socket.js";
import { gpioProcess } from "./services/gpio/gpio.js";
import "./services/print/print.js";
import "./services/browser/browser.js";
setTimeout(async () => {
const bluetoothSerialMonitors = import("./services/bluetooth/bluetooth.js");
const server = import("./services/rest/rest.js");
const { webSocketServer } = import("./services/socket/socket.js");
const { gpioProcess } = import("./services/gpio/gpio.js");
await import("./services/print/print.js");
await import("./services/browser/browser.js");

process.on("SIGINT", () => closeEverything(1));
process.on("SIGINT", () => closeEverything(1));

process.on("SIGTERM", () => closeEverything(0));
process.on("SIGTERM", () => closeEverything(0));

function closeEverything(eventId) {
bluetoothSerialMonitors.forEach((monitor) => monitor.kill());
server.close();
webSocketServer.clients.forEach((client) => client.close());
webSocketServer.close();
gpioProcess.kill();
function closeEverything(eventId) {
bluetoothSerialMonitors.forEach((monitor) => monitor.kill());
server.close();
webSocketServer.clients.forEach((client) => client.close());
webSocketServer.close();
gpioProcess.kill();

process.exit(eventId)
}
process.exit(eventId);
}
}, 30_000);

0 comments on commit 717399d

Please sign in to comment.