Skip to content

Commit

Permalink
hotfix: hackernews fork
Browse files Browse the repository at this point in the history
  • Loading branch information
aldy505 committed Nov 16, 2023
1 parent 7433c8b commit 923a515
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
30 changes: 16 additions & 14 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ const mongo = mongoose.createConnection(String(process.env.MONGO_URL), {
useNewUrlParser: true
});

// Fork processes
const hackernewsFork = fork(pathTo(import.meta.url, "./hackernews.js"), { detached: true });

function terminate(caller) {
const t = Date.now();
mongo.close();
bot.stop(caller);
hackernewsFork.kill();
terminal.info(`${caller}: ${Date.now() - t}ms`);
}

// Enable graceful stop, register to process;
process.once("SIGINT", () => terminate("SIGINT"));
process.once("SIGTERM", () => terminate("SIGTERM"));


async function main() {
mongo.on("connected", () => terminal.info("MongoDB connected"));

Expand Down Expand Up @@ -113,7 +129,6 @@ async function main() {
}
});

fork(pathTo("./hackernews.js"), { detached: false });

// For more information about what this is, please refer to:
// https://nodejs.org/api/process.html#process_process_memoryusage
Expand All @@ -128,16 +143,3 @@ async function main() {
}

main();

function terminate(caller) {
const t = Date.now();
mongo.close((err) => {
err && terminal.error(err);
});
bot.stop(caller);
terminal.info(`${caller}: ${Date.now() - t}ms`);
}

// Enable graceful stop
process.once("SIGINT", () => terminate("SIGINT"));
process.once("SIGTERM", () => terminate("SIGTERM"));
4 changes: 2 additions & 2 deletions src/hackernews.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Telegraf } from "telegraf";
import dotenv from "dotenv";
import { pathTo } from "#utils/path.js";
import { run } from "#services/hackernews.js";
import { sentry } from "#utils/logger.js";
import { run } from "#services/hackernews/index.js";
import { sentry } from "#utils/logger/index.js";

dotenv.config({ path: pathTo(import.meta.url, "../.env") });

Expand Down

0 comments on commit 923a515

Please sign in to comment.