diff --git a/tests/publish/testComment.ts b/tests/publish/testComment.ts new file mode 100644 index 0000000..136f4cf --- /dev/null +++ b/tests/publish/testComment.ts @@ -0,0 +1,109 @@ +import { Comment } from "../../src/rdrama/models/Comment"; +import * as readline from 'readline'; +import RedisCommentService from "../../src/redis/services/CommentService" +import RedisSessionManager from '../../src/redis/session/SessionManager'; + + +const comment: Comment = { + "author_id": 9978, + "author_name": "J", + "body": "!!oregon 3", + "body_html": "
!!oregon 3
", + "created_utc": 1712512562, + "deleted_utc": 0, + "distinguished": false, + "downvotes": 0, + "edited_utc": 0, + "id": 6227144, + "is_banned": false, + "is_bot": false, + "is_nsfw": false, + "level": 1, + "permalink": "/comment/6227144#context", + "pinned": null, + "post_id": 0, + "replies": [], + "reports": {}, + "score": 1, + "upvotes": 1 +} + + + +async function main(): Promise${line.trim()}
`; + + // Publish the updated comment to the Redis server + try { + const publishResult = await RedisCommentService.publishComment(comment); + console.log(`Comment published with result: ${publishResult}`); + } catch (error) { + console.error('Failed to publish comment:', error); + } + + rl.prompt(); + } + }).on('close', async () => { + console.log('Goodbye!'); + await redisManager.shutdown(); + process.exit(0); + }); +}; + + + +function setupProcessListeners(redisManager: RedisSessionManager) { + process.on('SIGINT', async () => { + console.log('SIGINT received. Shutting down gracefully...'); + await shutdownServices(redisManager); + }); + + process.on('SIGTERM', async () => { + console.log('SIGTERM received. Shutting down gracefully...'); + await shutdownServices(redisManager); + }); + + process.on('uncaughtException', async (error) => { + console.error('Uncaught Exception:', error); + await shutdownServices(redisManager); + process.exit(1); // Exit with error + }); + + process.on('unhandledRejection', async (reason, promise) => { + console.error('Unhandled Rejection at:', promise, 'reason:', reason); + await shutdownServices(redisManager); + process.exit(1); // Exit with error + }); +} + +async function shutdownServices(redisManager: RedisSessionManager) { + await redisManager.shutdown(); + console.log('Services shut down successfully.'); + process.exit(0); // Exit cleanly +} + +main(); \ No newline at end of file