-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from planetary-social/vanish_requests
Vanish requests
- Loading branch information
Showing
10 changed files
with
318 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,48 @@ | ||
import app from "./app.js"; | ||
import logger from "./logger.js"; | ||
import config from "../config/index.js"; | ||
import { | ||
getVanishRequestsRedisClient, | ||
getNip05RedisClient, | ||
} from "./getRedisClient.js"; | ||
import VanishSubscriber from "./vanishSubscriber.js"; | ||
|
||
app.listen(config.port, () => { | ||
const vanishRequestsRedisClient = await getVanishRequestsRedisClient(); | ||
const nip05RedisClient = await getNip05RedisClient(); | ||
|
||
const server = app.listen(config.port, () => { | ||
logger.info(`Server is running on port ${config.port}`); | ||
}); | ||
|
||
process.on("uncaughtException", (err) => { | ||
logger.fatal(err, "Uncaught exception detected"); | ||
const vanishSubscriber = new VanishSubscriber( | ||
vanishRequestsRedisClient, | ||
nip05RedisClient | ||
); | ||
vanishSubscriber.run(); | ||
|
||
async function gracefulShutdown() { | ||
logger.info("Graceful shutdown initiated..."); | ||
|
||
vanishSubscriber.stop(); | ||
|
||
while (vanishSubscriber.isRunning) { | ||
await new Promise((resolve) => setTimeout(resolve, 100)); | ||
} | ||
|
||
server.close(() => { | ||
process.exit(1); | ||
logger.info("Express server closed."); | ||
process.exit(0); | ||
}); | ||
} | ||
|
||
setTimeout(() => { | ||
process.abort(); | ||
}, 1000).unref(); | ||
process.exit(1); | ||
process.on("uncaughtException", (err) => { | ||
logger.fatal(err, "Uncaught exception detected"); | ||
gracefulShutdown(); | ||
}); | ||
|
||
process.on("unhandledRejection", (reason, promise) => { | ||
logger.error(reason, "An unhandled promise rejection was detected"); | ||
}); | ||
|
||
process.on("SIGINT", gracefulShutdown); | ||
process.on("SIGTERM", gracefulShutdown); |
Oops, something went wrong.